fluent-plugin-newrelic_metrics 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98e173f8902f292dd80e4ea3ea04f4aee9bf84cd
4
+ data.tar.gz: 8851e5668a74ff7837a2854f84a225db09ff2b88
5
+ SHA512:
6
+ metadata.gz: 442e8f72f288e1c99e9bbab1fe3cc3f9e2d6e7422c6258b189b241bfe070d5b13ca483999faac0361ac1435026eb6d01299746b8e82827bdf29a31c1be80bf50
7
+ data.tar.gz: 2f2e73098eee3a7925d51e73fc63782658264d86e141c62d1a49947114a29c3ae745b7d1d1cfbda9157ac40dae0c42a4f0ce1f64c1a564f186adde4374d3de51
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ Gemfile.lock
2
+ doc/
3
+ pkg/
4
+ tmp/
5
+ **/*.gem
6
+ .yardoc/
7
+ .bundle/
8
+ vendor/bundle/
9
+ .tags
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+
8
+ os:
9
+ - linux
10
+ - osx
11
+
12
+ gemfile:
13
+ - Gemfile
14
+
15
+ script: 'bundle exec rake test'
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title "fluent-plugin-newrelic_metrics Documentation" --protected
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'kramdown'
7
+ end
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # fluent-plugin-newrelic_metrics [![Build Status](https://secure.travis-ci.org/toyama0919/fluent-plugin-newrelic_metrics.png?branch=master)](http://travis-ci.org/toyama0919/fluent-plugin-newrelic_metrics)
2
+
3
+ NewrelicMetrics plugin for fluentd
4
+
5
+ ## Examples
6
+ ```
7
+ <source>
8
+ type newrelic_metrics
9
+ tag newrelic_applications.exsample
10
+ interval 1m
11
+ metrics applications # applications or servers
12
+ api_key "#{ENV['NEWRELIC_API_KEY']}"
13
+ </source>
14
+
15
+ <match newrelic_applications.exsample>
16
+ type stdout
17
+ </match>
18
+
19
+ <source>
20
+ type newrelic_metrics
21
+ tag newrelic_servers.exsample
22
+ interval 1m
23
+ metrics servers # applications or servers
24
+ api_key "#{ENV['NEWRELIC_API_KEY']}"
25
+ </source>
26
+
27
+ <match newrelic_servers.exsample>
28
+ type stdout
29
+ </match>
30
+ ```
31
+
32
+ #### output
33
+ ```
34
+ #TODO
35
+ ```
36
+
37
+ ## parameter
38
+
39
+ param | value|default
40
+ --------|------|------
41
+ interval|leftronic access key|1m
42
+ stream_name|leftronic stream name|test
43
+
44
+ ## Installation
45
+ ```
46
+ fluent-gem install fluent-plugin-newrelic_metrics
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new [Pull Request](../../pull/new/master)
56
+
57
+ ## Information
58
+
59
+ * [Homepage](https://github.com/toyama0919/fluent-plugin-newrelic_metrics)
60
+ * [Issues](https://github.com/toyama0919/fluent-plugin-newrelic_metrics/issues)
61
+ * [Documentation](http://rubydoc.info/gems/fluent-plugin-newrelic_metrics/frames)
62
+ * [Email](mailto:toyama0919@gmail.com)
63
+
64
+ ## Copyright
65
+
66
+ Copyright (c) 2015 Hiroshi Toyama
67
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
11
+
@@ -0,0 +1,28 @@
1
+ <source>
2
+ type forward
3
+ port 24224
4
+ </source>
5
+
6
+ <source>
7
+ type newrelic_metrics
8
+ tag newrelic_applications.exsample
9
+ interval 1m
10
+ metrics applications
11
+ api_key "#{ENV['NEWRELIC_API_KEY']}"
12
+ </source>
13
+
14
+ <match newrelic_applications.exsample>
15
+ type stdout
16
+ </match>
17
+
18
+ <source>
19
+ type newrelic_metrics
20
+ tag newrelic_servers.exsample
21
+ interval 1m
22
+ metrics servers
23
+ api_key "#{ENV['NEWRELIC_API_KEY']}"
24
+ </source>
25
+
26
+ <match newrelic_servers.exsample>
27
+ type stdout
28
+ </match>
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "fluent-plugin-newrelic_metrics"
5
+ gem.version = "0.0.1"
6
+ gem.summary = %q{Newrelic metrics input plugin for fluentd}
7
+ gem.description = %q{Newrelic metrics input plugin for fluentd}
8
+ gem.license = "MIT"
9
+ gem.authors = ["Hiroshi Toyama"]
10
+ gem.email = "toyama0919@gmail.com"
11
+ gem.homepage = "https://github.com/toyama0919/fluent-plugin-newrelic_metrics"
12
+
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_runtime_dependency "rest-client"
19
+
20
+ gem.add_development_dependency 'bundler', '~> 1.7.2'
21
+ gem.add_development_dependency 'fluentd', '~> 0.10.58'
22
+ gem.add_development_dependency 'pry', '~> 0.10.1'
23
+ gem.add_development_dependency 'rake', '~> 10.3.2'
24
+ gem.add_development_dependency 'rubocop', '~> 0.24.1'
25
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
26
+ gem.add_development_dependency 'yard', '~> 0.8'
27
+ end
@@ -0,0 +1,64 @@
1
+ module Fluent
2
+ class NewrelicMetricsInput < Fluent::Input
3
+ PREFIX = 'https://api.newrelic.com/v2'
4
+ Plugin.register_input 'newrelic_metrics', self
5
+
6
+ # Define `router` method of v0.12 to support v0.10 or earlier
7
+ unless method_defined?(:router)
8
+ define_method("router") { Fluent::Engine }
9
+ end
10
+
11
+ def initialize
12
+ super
13
+ require 'rest-client'
14
+ end
15
+
16
+ config_param :tag, :string
17
+ config_param :api_key, :string
18
+ config_param :metrics, :string
19
+ config_param :alert_policy_id, :integer, default: nil
20
+ config_param :interval, :time, default: '1m'
21
+
22
+ def configure(conf)
23
+ super
24
+ @state = {}
25
+ end
26
+
27
+ def start
28
+ @thread = Thread.new(&method(:run))
29
+ end
30
+
31
+ def shutdown
32
+ Thread.kill(@thread)
33
+ end
34
+
35
+ def run
36
+ loop do
37
+ Thread.new(&method(:emit_newrelic_metrics))
38
+ sleep @interval
39
+ end
40
+ end
41
+
42
+ def emit_newrelic_metrics
43
+ begin
44
+ results = RestClient.get PREFIX + "/#{@metrics}.json", 'X-Api-Key' => @api_key
45
+ records = JSON.parse(results)[@metrics]
46
+ if @alert_policy_id
47
+ records = records.select{ |record|
48
+ record['links']['alert_policy'] == @alert_policy_id
49
+ }
50
+ end
51
+ records.each do |record|
52
+ before_last_reported_at = @state["#{record['id']}"]
53
+ last_reported_at = Time.parse(record['last_reported_at'])
54
+ if before_last_reported_at.nil? || (before_last_reported_at < last_reported_at)
55
+ router.emit @tag, last_reported_at, record
56
+ @state["#{record['id']}"] = last_reported_at
57
+ end
58
+ end
59
+ rescue => e
60
+ log.error e
61
+ end
62
+ end
63
+ end
64
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ require 'fluent/plugin/in_newrelic_metrics'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ class NewrelicMetricsInputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ def create_driver(conf)
9
+ Fluent::Test::InputTestDriver.new(Fluent::NewrelicMetricsInput).configure(conf)
10
+ end
11
+
12
+ def test_configure_full
13
+ d = create_driver %q{
14
+ tag test
15
+ interval 10m
16
+ }
17
+
18
+ assert_equal 'test', d.instance.tag
19
+ assert_equal 10 * 60, d.instance.interval
20
+ assert_equal 'hoge', d.instance.instance_variable_get(:@hoge)
21
+ end
22
+
23
+ def test_configure_error_when_config_is_empty
24
+ assert_raise(Fluent::ConfigError) do
25
+ create_driver ''
26
+ end
27
+ end
28
+
29
+ def test_emit
30
+ d = create_driver
31
+
32
+ d.run do
33
+ sleep 2
34
+ end
35
+
36
+ emits = d.emits
37
+ assert_equal true, emits.length > 0
38
+ assert_equal "tag1", emits[0].first
39
+ assert_equal ({"k1"=>"ok"}), emits[0].last
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-newrelic_metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroshi Toyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluentd
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.58
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.58
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 10.3.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 10.3.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.24.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.24.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubygems-tasks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ description: Newrelic metrics input plugin for fluentd
126
+ email: toyama0919@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - ".document"
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - ".yardopts"
135
+ - Gemfile
136
+ - README.md
137
+ - Rakefile
138
+ - exsample/exsample.conf
139
+ - fluent-plugin-newrelic_metrics.gemspec
140
+ - lib/fluent/plugin/in_newrelic_metrics.rb
141
+ - test/helper.rb
142
+ - test/plugin/test_in_newrelic_metrics.rb
143
+ homepage: https://github.com/toyama0919/fluent-plugin-newrelic_metrics
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.4.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Newrelic metrics input plugin for fluentd
167
+ test_files:
168
+ - test/helper.rb
169
+ - test/plugin/test_in_newrelic_metrics.rb
170
+ has_rdoc: