fluent-plugin-storm 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7aad4d2fdb80bf541670b988ba0fac3353695c5
4
+ data.tar.gz: 8246d9a000ef2064aeee314ccd87e0ffbd5582e4
5
+ SHA512:
6
+ metadata.gz: 7385db881e037d095ce54187a2ce682f26acbc495d4586a06a53299edf94f53a9eea241460b874989db102dae8758ab91f0dad88656159007872e06cc404cf45
7
+ data.tar.gz: 92179e8969654abb53492a1826bf2c22d15391da44e2e35f3ea46420bbae8697eb5c42dc44dab3c07eaaa6795ad20843c5fee59a1a93ecf6cdef21509d65fbc7
@@ -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.
@@ -0,0 +1,43 @@
1
+ ## fluent-plugin-storm
2
+
3
+ [storm](https://storm.apache.org/) stats input plugin
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-storm'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-storm
18
+
19
+ ## Configuration
20
+
21
+ ### Example
22
+
23
+ <source>
24
+ type storm
25
+ tag storm
26
+ interval 60
27
+ url http://localhost:8080
28
+ window 600
29
+ sys 0
30
+ </source>
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new [Pull Request](../../pull/new/master)
39
+
40
+ ## Copyright
41
+
42
+ Copyright (c) 2015 Hidenori Suzuki. See [LICENSE](LICENSE) for details.
43
+
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,26 @@
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-storm'
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 = 'storm stats input plugin'
12
+ spec.homepage = 'https://github.com/niyonmaruz/fluent-plugin-storm'
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 'test-unit'
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,98 @@
1
+ # coding: utf-8
2
+ module Fluent
3
+ class StormInput < Fluent::Input
4
+ Fluent::Plugin.register_input('storm', self)
5
+ config_param :tag, :string, default: 'storm'
6
+ config_param :interval, :integer, default: 60
7
+ config_param :url, :string, default: 'http://localhost:8080'
8
+ config_param :window, :string, :default => nil
9
+ config_param :sys, :string, :default => nil
10
+
11
+ def initialize
12
+ super
13
+ require 'net/http'
14
+ require 'uri'
15
+ require 'json'
16
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+ end
21
+
22
+ def start
23
+ @loop = Coolio::Loop.new
24
+ @tw = TimerWatcher.new(interval, true, log, &method(:execute))
25
+ @tw.attach(@loop)
26
+ @thread = Thread.new(&method(:run))
27
+ end
28
+
29
+ def shutdown
30
+ @tw.detach
31
+ @loop.stop
32
+ @thread.join
33
+ end
34
+
35
+ def run
36
+ @loop.run
37
+ rescue => e
38
+ @log.error 'unexpected error', error: e.to_s
39
+ @log.error_backtrace
40
+ end
41
+
42
+ private
43
+
44
+ def execute
45
+ @time = Engine.now
46
+ record = Hash.new(0)
47
+ uri = URI.parse("#{@url}/api/v1/topology/summary")
48
+ @log.debug(uri)
49
+ Net::HTTP.start(uri.host, uri.port) do |http|
50
+ request = Net::HTTP::Get.new(uri.request_uri)
51
+ http.request(request) do |response|
52
+ record = JSON.parse(response.body) rescue next
53
+ record["topologies"].each do |line|
54
+ topology_id = line["id"]
55
+ #@log.debug(line["id"])
56
+ uri = URI.parse("#{@url}/api/v1/topology/#{topology_id}")
57
+ if @window && @sys
58
+ uri = URI.parse("#{@url}/api/v1/topology/#{topology_id}?window=#{@window}&sys=#{@sys}")
59
+ elsif @window
60
+ uri = URI.parse("#{@url}/api/v1/topology/#{topology_id}?window=#{@window}")
61
+ elsif @sys
62
+ uri = URI.parse("#{@url}/api/v1/topology/#{topology_id}?sys=#{@sys}")
63
+ end
64
+ #@log.debug(uri)
65
+ Net::HTTP.start(uri.host, uri.port) do |http|
66
+ request = Net::HTTP::Get.new(uri.request_uri)
67
+ http.request(request) do |response|
68
+ record = JSON.parse(response.body) rescue next
69
+ record.delete("visualizationTable")
70
+ record.delete("configuration")
71
+ end
72
+ end
73
+ @log.debug(record)
74
+ Engine.emit(@tag, @time, record)
75
+ end
76
+ end
77
+ end
78
+ rescue => e
79
+ @log.error('faild to run', error: e.to_s, error_class: e.class.to_s)
80
+ @log.error_backtrace
81
+ end
82
+
83
+ class TimerWatcher < Coolio::TimerWatcher
84
+ def initialize(interval, repeat, log, &callback)
85
+ @log = log
86
+ @callback = callback
87
+ super(interval, repeat)
88
+ end
89
+
90
+ def on_timer
91
+ @callback.call
92
+ rescue => e
93
+ @log.error e.to_s
94
+ @log.error_backtrace
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+ BASE_CONFIG = %(
3
+ type storm
4
+ tag hoge
5
+ )
6
+
7
+ CONFIG = BASE_CONFIG + %(
8
+ interval 1
9
+ )
10
+
11
+ describe Fluent::StormInput 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::StormInput)
19
+ end
20
+
21
+ context 'test of test' do
22
+ it 'getting 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::StormInput)
33
+ .configure(config)
34
+ end
35
+
36
+ before do
37
+ end
38
+
39
+ describe 'interval test' do
40
+ before do
41
+ end
42
+ context 'in case interval=1' do
43
+ let(:config) { BASE_CONFIG + 'interval 1' }
44
+
45
+ it '2 execute in 2 sec' do
46
+ expect(d.instance).to receive(:execute).exactly(2)
47
+ d.run { sleep 2.0 }
48
+ end
49
+ end
50
+
51
+ context 'in case interval=2' do
52
+ let(:config) { BASE_CONFIG + 'interval 2' }
53
+ it '1 execute in sec' 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_storm'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-storm
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-29 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: test-unit
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: storm stats input plugin
84
+ email:
85
+ - hidenori.suzuki@yahoo.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - fluent-plugin-storm.gemspec
97
+ - lib/fluent/plugin/in_storm.rb
98
+ - spec/fluent/plugin/in_storm_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: https://github.com/niyonmaruz/fluent-plugin-storm
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: a fluent plugin
124
+ test_files:
125
+ - spec/fluent/plugin/in_storm_spec.rb
126
+ - spec/spec_helper.rb