fluent-plugin-jmx 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: 345709894e5eeae6fb7f3fbb1fad41417e801135
4
+ data.tar.gz: 2a14b1d2d10d0565625b2f1e6979aa882d6eeb03
5
+ SHA512:
6
+ metadata.gz: e1bb54024b16beefcb995c92cc0439fc7d988c9281c7ad1613e123f9e0c277b271b07091d5115da64e903aaa6781dcc0647cc4265a183f6ce6fa409f95f3037f
7
+ data.tar.gz: c1dbf86d62db968f50c9843f0876b35b79f562b100ba0f666a03d6792c6d209b7672c853107033700e85067bf6822c493d389b24db66ce01f4585a0c1972cf38
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ vendor/
4
+ *.bundle
5
+ *.git
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
4
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ group :development, :test do
5
+ gem 'rubocop', require: false
6
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Hidenori Suzuki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ ## fluent-plugin-jmx
2
+
3
+ [jolokia](https://jolokia.org/) input plugin
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-jmx'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-jmx
18
+
19
+ ## Configuration
20
+
21
+ ### Example
22
+
23
+ <source>
24
+ type jmx
25
+ tag jmx.memory
26
+ url http://127.0.0.1:38778/jolokia
27
+ mbean java.lang:type=Memory
28
+ attribute HeapMemoryUsage
29
+ interval 60
30
+ inner_path used
31
+ </match>
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new [Pull Request](../../pull/new/master)
40
+
41
+ ## Copyright
42
+
43
+ Copyright (c) 2015 Hidenori Suzuki. See [LICENSE](LICENSE) for details.
44
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'fluent-plugin-jmx'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Hidenori Suzuki']
9
+ spec.email = ['hidenori.suzuki@yahoo.com']
10
+ spec.summary = 'a fluent plugin'
11
+ spec.description = 'jolokia input plugin'
12
+ spec.homepage = 'https://github.com/6pongi/fluent-plugin-jmx'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'fluentd', '~> 0.10.0'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec'
25
+ end
@@ -0,0 +1,88 @@
1
+ # coding: utf-8
2
+ module Fluent
3
+ class JmxInput < Fluent::Input
4
+ Fluent::Plugin.register_input('jmx', self)
5
+ config_param :tag, :string, default: 'jmx'
6
+ config_param :interval, :integer, default: 60
7
+ config_param :url, :string, default: 'http://127.0.0.1:8778/jolokia'
8
+ config_param :mbean, :string, default: 'java.lang:type=Memory'
9
+ config_param :attribute, :string, :default => nil
10
+ config_param :inner_path, :string, :default => nil
11
+
12
+ def initialize
13
+ super
14
+ require 'net/http'
15
+ require 'uri'
16
+ require 'json'
17
+ end
18
+
19
+ def configure(conf)
20
+ super
21
+ end
22
+
23
+ def start
24
+ @loop = Coolio::Loop.new
25
+ @tw = TimerWatcher.new(interval, true, log, &method(:execute))
26
+ @tw.attach(@loop)
27
+ @thread = Thread.new(&method(:run))
28
+ end
29
+
30
+ def shutdown
31
+ @tw.detach
32
+ @loop.stop
33
+ @thread.join
34
+ end
35
+
36
+ def run
37
+ @loop.run
38
+ rescue => e
39
+ @log.error 'unexpected error', error: e.to_s
40
+ @log.error_backtrace
41
+ end
42
+
43
+ private
44
+
45
+ def execute
46
+ @time = Engine.now
47
+ record = _get_record
48
+ @log.debug(record)
49
+ Engine.emit(@tag, @time, record)
50
+ rescue => e
51
+ @log.error('faild to run', error: e.to_s, error_class: e.class.to_s)
52
+ @log.error_backtrace
53
+ end
54
+
55
+ def _get_record
56
+ record = Hash.new(0)
57
+ uri = URI.parse("#{@url}/read/#{@mbean}/#{@attribute}")
58
+ if @attribute && @inner_path
59
+ uri = URI.parse("#{@url}/read/#{@mbean}/#{@attribute}/#{@inner_path}")
60
+ end
61
+ @log.debug(uri)
62
+ Net::HTTP.start(uri.host, uri.port) do |http|
63
+ request = Net::HTTP::Get.new(uri.request_uri)
64
+ http.request(request) do |response|
65
+ record = JSON.parse(response.body) rescue next
66
+ record.delete("value"["Verbose"])
67
+ @log.debug(response.body)
68
+ end
69
+ end
70
+ record
71
+ end
72
+
73
+ class TimerWatcher < Coolio::TimerWatcher
74
+ def initialize(interval, repeat, log, &callback)
75
+ @log = log
76
+ @callback = callback
77
+ super(interval, repeat)
78
+ end
79
+
80
+ def on_timer
81
+ @callback.call
82
+ rescue => e
83
+ @log.error e.to_s
84
+ @log.error_backtrace
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+ BASE_CONFIG = %(
3
+ type jmx
4
+ tag hoge
5
+ )
6
+
7
+ CONFIG = BASE_CONFIG + %(
8
+ interval 1
9
+ )
10
+
11
+ describe Fluent::JmxInput do
12
+ before do
13
+ Fluent::Test.setup
14
+ end
15
+
16
+ describe '#configure' do
17
+ let(:d) do
18
+ Fluent::Test::InputTestDriver.new(Fluent::JmxInput)
19
+ end
20
+
21
+ context 'テストのテスト' do
22
+ it 'configが取得できること' do
23
+ instance = d.configure(CONFIG).instance
24
+ expect(instance.interval).to eq 1
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ describe '#run' do
31
+ let(:d) do
32
+ Fluent::Test::InputTestDriver.new(Fluent::JmxInput)
33
+ .configure(config)
34
+ end
35
+
36
+ before do
37
+ end
38
+
39
+ describe 'interval確認' do
40
+ before do
41
+ end
42
+ context 'intervalが1秒の場合' do
43
+ let(:config) { BASE_CONFIG + 'interval 1' }
44
+
45
+ it '2秒間にexecuteを2回コールすること。' do
46
+ expect(d.instance).to receive(:execute).exactly(2)
47
+ d.run { sleep 2.0 }
48
+ end
49
+ end
50
+
51
+ context 'intervalが2秒の場合' do
52
+ let(:config) { BASE_CONFIG + 'interval 2' }
53
+ it '2秒間にexecuteを1回コールすること。' do
54
+ expect(d.instance).to receive(:execute).exactly(1)
55
+ d.run { sleep 2.0 }
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,2 @@
1
+ require 'fluent/test'
2
+ require 'fluent/plugin/in_jmx'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-jmx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hidenori Suzuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.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.10.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'
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: jolokia input plugin
70
+ email:
71
+ - hidenori.suzuki@yahoo.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - fluent-plugin-jmx.gemspec
83
+ - lib/fluent/plugin/in_jmx.rb
84
+ - spec/fluent/plugin/in_jmx_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: https://github.com/6pongi/fluent-plugin-jmx
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: a fluent plugin
110
+ test_files:
111
+ - spec/fluent/plugin/in_jmx_spec.rb
112
+ - spec/spec_helper.rb