fluent-plugin-dstat 0.3.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 689378189e1225c23f9d6e083077f40d3760833d
4
- data.tar.gz: f8fb4a49ab1d3586ab5ec4c72fb6c157c5d4a163
2
+ SHA256:
3
+ metadata.gz: dbcaf16559713e0913d2160ae9b2b081848474984d42b5e3227582a6eb9c2b4a
4
+ data.tar.gz: d39be7e49a80312eefd977137c19cf72a9bca3edae92be5c424a4093c2202869
5
5
  SHA512:
6
- metadata.gz: 4dd33c9bbad811a3f60bb0a352d8294829f4ec87e5dd8d52d68fa05109fd550ef7ceb40f07368c023133938f0a45fc0509e1422575b377893569cb7f2f8bc7d7
7
- data.tar.gz: 0a0a1cb719f99b1cb0e1944a1782e556e15733924f588ff06db27ae7d6b7d84e04c9689934c35fa6487c6b8e5ac3bfc5b20240f3483ff4afa69d77576c408c01
6
+ metadata.gz: ac260e611e6a09257d8c4bc27ea4092fa17a124d4983da273f9fa897994fd34d38c31330e6cbe99181055262ae61463241177f67a10eecaf4dfeeb349c4107e0
7
+ data.tar.gz: 1edcf9ba3e298ef4dc442718bb6611abbe1ae8d1a0d19dc19c7be18c88bbd04a5365870b0db4509c4f61eca9953cd600b1c8aba25a210c6129cf4c431dcd21f8
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-dstat"
6
- s.version = "0.3.3"
6
+ s.version = "1.0.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
@@ -31,24 +31,9 @@ Gem::Specification.new do |s|
31
31
  s.rubygems_version = "2.4.5"
32
32
  s.summary = "Dstat Input plugin for Fluent event collector"
33
33
 
34
- if s.respond_to? :specification_version then
35
- s.specification_version = 4
36
-
37
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
- s.add_runtime_dependency(%q<fluentd>, [">= 0.10.7", "< 2"])
39
- s.add_runtime_dependency(%q<rdoc>, [">= 0"])
40
- s.add_development_dependency(%q<test-unit>, [">= 3.0.0"])
41
- s.add_development_dependency(%q<bundler>, ["~> 1.0"])
42
- else
43
- s.add_runtime_dependency(%q<fluentd>, [">= 0.10.7", "< 2"])
44
- s.add_runtime_dependency(%q<rdoc>, [">= 0"])
45
- s.add_dependency(%q<test-unit>, [">= 3.0.0"])
46
- s.add_dependency(%q<bundler>, ["~> 1.0"])
47
- end
48
- else
49
- s.add_runtime_dependency(%q<fluentd>, [">= 0.10.7", "< 2"])
50
- s.add_runtime_dependency(%q<rdoc>, [">= 0"])
51
- s.add_dependency(%q<test-unit>, [">= 3.0.0"])
52
- s.add_dependency(%q<bundler>, ["~> 1.0"])
53
- end
34
+ s.add_runtime_dependency(%q<fluentd>, [">= 0.14.0", "< 2"])
35
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
36
+ s.add_development_dependency(%q<test-unit>, [">= 3.0.0"])
37
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
38
+ s.add_development_dependency(%q<rake>, ["~> 12.0"])
54
39
  end
@@ -1,9 +1,11 @@
1
- require 'fluent/input'
1
+ require 'fluent/plugin/input'
2
2
 
3
- module Fluent
3
+ module Fluent::Plugin
4
4
  class DstatInput < Input
5
5
 
6
- Plugin.register_input('dstat', self)
6
+ Fluent::Plugin.register_input('dstat', self)
7
+
8
+ helpers :timer, :event_loop
7
9
 
8
10
  def initialize
9
11
  super
@@ -24,6 +26,10 @@ module Fluent
24
26
  end
25
27
  end
26
28
 
29
+ unless method_defined?(:log)
30
+ define_method("log") { $log }
31
+ end
32
+
27
33
  desc "the tag of event"
28
34
  config_param :tag, :string
29
35
  desc "dstat command path"
@@ -46,47 +52,35 @@ module Fluent
46
52
  begin
47
53
  `#{@dstat_path} --version`
48
54
  rescue Errno::ENOENT
49
- raise ConfigError, "'#{@dstat_path}' command not found. Install dstat before run fluentd"
55
+ raise Fluent::ConfigError, "'#{@dstat_path}' command not found. Install dstat before run fluentd"
50
56
  end
51
57
  end
52
58
 
53
59
  def check_dstat
54
60
  now = Time.now
55
61
  if now - @last_time > @delay * 3
56
- $log.info "Process dstat(#{@pid}) is stopped. Last updated: #{@last_time}"
62
+ log.info "Process dstat(#{@pid}) is stopped. Last updated: #{@last_time}"
57
63
  restart
58
64
  end
59
65
  end
60
66
 
61
67
  def start
68
+ super
62
69
  system("mkfifo #{@tmp_file}")
63
70
  @io = IO.popen(@command, "r")
64
71
  @pid = @io.pid
65
72
 
66
- @loop = Coolio::Loop.new
67
73
  @dw = DstatCSVWatcher.new(@tmp_file, &method(:receive_lines))
68
- @dw.attach(@loop)
69
- @tw = TimerWatcher.new(1, true, &method(:check_dstat))
70
- @tw.attach(@loop)
71
- @thread = Thread.new(&method(:run))
74
+ event_loop_attach(@dw)
75
+ @tw = timer_execute(:in_dstat_timer, 1, &method(:check_dstat))
72
76
  end
73
77
 
74
78
  def shutdown
75
79
  Process.kill(:TERM, @pid)
76
80
  @dw.detach
77
81
  @tw.detach
78
- @loop.stop
79
- @thread.join
80
82
  File.delete(@tmp_file)
81
- end
82
-
83
- def run
84
- begin
85
- @loop.run
86
- rescue
87
- $log.error "unexpected error", :error=>$!.to_s
88
- $log.error_backtrace
89
- end
83
+ super
90
84
  end
91
85
 
92
86
  def restart
@@ -94,8 +88,8 @@ module Fluent
94
88
  begin
95
89
  Process.kill(:TERM, @pid)
96
90
  rescue Errno::ESRCH => e
97
- $log.error "unexpected death of a child process", :error=>e.to_s
98
- $log.error_backtrace
91
+ log.error "unexpected death of a child process", :error=>e.to_s
92
+ log.error_backtrace
99
93
  end
100
94
  @dw.detach
101
95
  @tw.detach
@@ -104,9 +98,8 @@ module Fluent
104
98
  @io = IO.popen(@command, "r")
105
99
  @pid = @io.pid
106
100
  @dw = DstatCSVWatcher.new(@tmp_file, &method(:receive_lines))
107
- @dw.attach(@loop)
108
- @tw = TimerWatcher.new(1, true, &method(:check_dstat))
109
- @tw.attach(@loop)
101
+ event_loop_attach(@dw)
102
+ @tw = timer_execute(:in_dstat_timer, 1, &method(:check_dstat))
110
103
  end
111
104
 
112
105
  def receive_lines(lines)
@@ -144,7 +137,7 @@ module Fluent
144
137
  'hostname' => @hostname,
145
138
  'dstat' => data
146
139
  }
147
- router.emit(@tag, Engine.now, record)
140
+ router.emit(@tag, Fluent::Engine.now, record)
148
141
  end
149
142
  @line_number += 1
150
143
  @last_time = Time.now
@@ -175,19 +168,5 @@ module Fluent
175
168
  # will be readable on next event
176
169
  end
177
170
  end
178
-
179
- class TimerWatcher < Cool.io::TimerWatcher
180
- def initialize(interval, repeat, &check_dstat)
181
- @check_dstat = check_dstat
182
- super(interval, repeat)
183
- end
184
-
185
- def on_timer
186
- @check_dstat.call
187
- rescue
188
- $log.error $!.to_s
189
- $log.error_backtrace
190
- end
191
- end
192
171
  end
193
172
  end
@@ -13,6 +13,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
13
  $LOAD_PATH.unshift(File.dirname(__FILE__))
14
14
 
15
15
  require 'fluent/test'
16
+ require 'fluent/test/driver/input'
16
17
  require 'fluent/plugin/in_dstat'
17
18
 
18
19
  class Test::Unit::TestCase
@@ -20,7 +20,7 @@ class DstatInputTest < Test::Unit::TestCase
20
20
  ]
21
21
 
22
22
  def create_driver(conf=CONFIG)
23
- Fluent::Test::InputTestDriver.new(Fluent::DstatInput).configure(conf)
23
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::DstatInput).configure(conf)
24
24
  end
25
25
 
26
26
  def test_configure
@@ -44,19 +44,17 @@ class DstatInputTest < Test::Unit::TestCase
44
44
  def emit_with_conf(conf)
45
45
  d = create_driver(conf)
46
46
 
47
- d.run do
48
- sleep 2
49
- end
47
+ d.run(expect_emits: 1)
50
48
 
51
49
  length = `dstat #{d.instance.option} #{d.instance.delay} 1`.split("\n")[0].split("\s").length
52
50
  puts `dstat #{d.instance.option} #{d.instance.delay} 3`
53
51
 
54
- emits = d.emits
55
- assert_equal true, emits.length > 0
56
- assert_equal length, emits[0][2]['dstat'].length
52
+ events = d.events
53
+ assert_equal true, events.length > 0
54
+ assert_equal length, events[0][2]['dstat'].length
57
55
 
58
56
  puts "--- #{d.instance.option} ---"
59
- puts emits[0][2]
57
+ puts events[0][2]
60
58
  puts "--- end ---"
61
59
  end
62
60
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-dstat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shunsuke Mikami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-11 00:00:00.000000000 Z
11
+ date: 2018-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.7
19
+ version: 0.14.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.10.7
29
+ version: 0.14.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
@@ -37,7 +37,7 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
- type: :runtime
40
+ type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '1.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '12.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '12.0'
75
89
  description:
76
90
  email: shun0102@gmail.com
77
91
  executables: []
@@ -111,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
125
  version: '0'
112
126
  requirements: []
113
127
  rubyforge_project:
114
- rubygems_version: 2.5.1
128
+ rubygems_version: 2.7.6
115
129
  signing_key:
116
130
  specification_version: 4
117
131
  summary: Dstat Input plugin for Fluent event collector
118
132
  test_files: []
119
- has_rdoc: