fluent-plugin-dstat 0.3.2 → 0.3.3

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
2
  SHA1:
3
- metadata.gz: da7754b1412274c5b20c0fdd8090f141e45ee5c4
4
- data.tar.gz: a1fdcaaa0583d70f1c4aaca6ba6f9538aadda82d
3
+ metadata.gz: 689378189e1225c23f9d6e083077f40d3760833d
4
+ data.tar.gz: f8fb4a49ab1d3586ab5ec4c72fb6c157c5d4a163
5
5
  SHA512:
6
- metadata.gz: 7bee0b4b8a2139f84eceff5d3941529db3ca17e2330d10b013efb30692c0646528f98e0f8dedf02005cdad6ad50a9c4d20b7c0cdd396bf5fdd16f29e8fc7d026
7
- data.tar.gz: df21f44396dd13cce329b12e0437e8dd1653c8808223a163d1c731da8b7505436bd31db71179c439936195c1ffa0f1cd1294487e60ab0cbe3dd741b32e75b21e
6
+ metadata.gz: 4dd33c9bbad811a3f60bb0a352d8294829f4ec87e5dd8d52d68fa05109fd550ef7ceb40f07368c023133938f0a45fc0509e1422575b377893569cb7f2f8bc7d7
7
+ data.tar.gz: 0a0a1cb719f99b1cb0e1944a1782e556e15733924f588ff06db27ae7d6b7d84e04c9689934c35fa6487c6b8e5ac3bfc5b20240f3483ff4afa69d77576c408c01
data/README.md CHANGED
@@ -10,7 +10,7 @@ This plugin use Dstat, so you need to install Dstat before using this plugin.
10
10
 
11
11
  ```
12
12
  <source>
13
- type dstat
13
+ @type dstat
14
14
  tag dstat
15
15
  option -c
16
16
  delay 3
@@ -23,19 +23,21 @@ This plugin use Dstat, so you need to install Dstat before using this plugin.
23
23
  * option for dstat command (default: -fcdnm)
24
24
 
25
25
  * tag
26
- * supported ${hostname} placeholder powered by [Fluent::Mixin::RewriteTagName](https://github.com/y-ken/fluent-mixin-rewrite-tag-name)
26
+ * the tag of event. You can embed hostname by `#{}` feature, e.g. `tag "dstat.#{Socket.gethostname}"`.
27
27
 
28
28
  ## Output Format
29
29
 
30
30
  When you use option -a, you get structured output data like below.
31
31
 
32
- {
32
+ ```
33
+ {
33
34
  "hostname":"tsukuba000",
34
- dstat":{"total cpu usage":"usr":"0.0","sys":"0.0","idl":"100.0","wai":"0.0","hiq":"0.0","siq":"0.0"},
35
+ "dstat":{"total cpu usage":"usr":"0.0","sys":"0.0","idl":"100.0","wai":"0.0","hiq":"0.0","siq":"0.0"},
35
36
  "dsk/total":{"read":"0.0","writ":"0.0"},"net/total":{"recv":"148.0","send":"164.0"},
36
37
  "paging":{"in":"0.0","out":"0.0"},
37
38
  "system":{"int":"16.333","csw":"29.0"}}
38
- }
39
+ }
40
+ ```
39
41
 
40
42
  ## Supported options
41
43
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -3,12 +3,11 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-dstat"
6
- s.version = "0.3.2"
6
+ s.version = "0.3.3"
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"]
10
10
  s.authors = ["Shunsuke Mikami"]
11
- s.date = "2015-08-15"
12
11
  s.email = "shun0102@gmail.com"
13
12
  s.license = "Apache-2.0"
14
13
  s.extra_rdoc_files = [
@@ -36,20 +35,17 @@ Gem::Specification.new do |s|
36
35
  s.specification_version = 4
37
36
 
38
37
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
- s.add_runtime_dependency(%q<fluent-mixin-rewrite-tag-name>, [">= 0"])
40
38
  s.add_runtime_dependency(%q<fluentd>, [">= 0.10.7", "< 2"])
41
39
  s.add_runtime_dependency(%q<rdoc>, [">= 0"])
42
40
  s.add_development_dependency(%q<test-unit>, [">= 3.0.0"])
43
41
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
44
42
  else
45
- s.add_runtime_dependency(%q<fluent-mixin-rewrite-tag-name>, [">= 0"])
46
43
  s.add_runtime_dependency(%q<fluentd>, [">= 0.10.7", "< 2"])
47
44
  s.add_runtime_dependency(%q<rdoc>, [">= 0"])
48
45
  s.add_dependency(%q<test-unit>, [">= 3.0.0"])
49
46
  s.add_dependency(%q<bundler>, ["~> 1.0"])
50
47
  end
51
48
  else
52
- s.add_runtime_dependency(%q<fluent-mixin-rewrite-tag-name>, [">= 0"])
53
49
  s.add_runtime_dependency(%q<fluentd>, [">= 0.10.7", "< 2"])
54
50
  s.add_runtime_dependency(%q<rdoc>, [">= 0"])
55
51
  s.add_dependency(%q<test-unit>, [">= 3.0.0"])
@@ -1,5 +1,4 @@
1
1
  require 'fluent/input'
2
- require 'fluent/mixin/rewrite_tag_name'
3
2
 
4
3
  module Fluent
5
4
  class DstatInput < Input
@@ -14,7 +13,6 @@ module Fluent
14
13
  @first_keys = []
15
14
  @second_keys = []
16
15
  @data_array = []
17
- @max_lines = 100
18
16
  @last_time = Time.now
19
17
  end
20
18
 
@@ -26,7 +24,7 @@ module Fluent
26
24
  end
27
25
  end
28
26
 
29
- desc "supported ${hostname} placeholder powered by Fluent::Mixin::RewriteTagName"
27
+ desc "the tag of event"
30
28
  config_param :tag, :string
31
29
  desc "dstat command path"
32
30
  config_param :dstat_path, :string, :default => "dstat"
@@ -35,25 +33,33 @@ module Fluent
35
33
  desc "Run dstat command every `delay` seconds"
36
34
  config_param :delay, :integer, :default => 1
37
35
  desc "Write dstat result to this file"
38
- config_param :tmp_file, :string, :default => "/tmp/dstat.csv"
36
+ config_param :tmp_file, :string, :default => "/tmp/fluent-plugin-dstat.fifo"
39
37
  desc "hostname command path"
40
38
  config_param :hostname_command, :string, :default => "hostname"
41
39
 
42
- include Fluent::Mixin::RewriteTagName
43
-
44
40
  def configure(conf)
45
41
  super
46
42
 
47
- @command = "#{@dstat_path} #{@option} --output #{@tmp_file} #{@delay}"
43
+ @command = "#{@dstat_path} #{@option} --nocolor --output #{@tmp_file} #{@delay} > /dev/null 2>&1"
48
44
  @hostname = `#{@hostname_command}`.chomp!
45
+
46
+ begin
47
+ `#{@dstat_path} --version`
48
+ rescue Errno::ENOENT
49
+ raise ConfigError, "'#{@dstat_path}' command not found. Install dstat before run fluentd"
50
+ end
49
51
  end
50
52
 
51
53
  def check_dstat
52
- restart if (Time.now - @last_time) > @delay*3
54
+ now = Time.now
55
+ if now - @last_time > @delay * 3
56
+ $log.info "Process dstat(#{@pid}) is stopped. Last updated: #{@last_time}"
57
+ restart
58
+ end
53
59
  end
54
60
 
55
61
  def start
56
- touch_or_truncate(@tmp_file)
62
+ system("mkfifo #{@tmp_file}")
57
63
  @io = IO.popen(@command, "r")
58
64
  @pid = @io.pid
59
65
 
@@ -94,7 +100,6 @@ module Fluent
94
100
  @dw.detach
95
101
  @tw.detach
96
102
  @line_number = 0
97
- touch_or_truncate(@tmp_file)
98
103
 
99
104
  @io = IO.popen(@command, "r")
100
105
  @pid = @io.pid
@@ -104,14 +109,6 @@ module Fluent
104
109
  @tw.attach(@loop)
105
110
  end
106
111
 
107
- def touch_or_truncate(file)
108
- if File.exist?(file)
109
- File.truncate(file, 0)
110
- else
111
- `touch #{file}`
112
- end
113
- end
114
-
115
112
  def receive_lines(lines)
116
113
  lines.each do |line|
117
114
  next if line == ""
@@ -147,18 +144,8 @@ module Fluent
147
144
  'hostname' => @hostname,
148
145
  'dstat' => data
149
146
  }
150
- emit_tag = @tag.dup
151
- filter_record(emit_tag, Engine.now, record)
152
- router.emit(emit_tag, Engine.now, record)
153
- end
154
-
155
- if (@line_number % @max_lines) == (@max_lines - 1)
156
- @dw.detach
157
- File.truncate(@tmp_file, 0)
158
- @dw = DstatCSVWatcher.new(@tmp_file, &method(:receive_lines))
159
- @dw.attach(@loop)
147
+ router.emit(@tag, Engine.now, record)
160
148
  end
161
-
162
149
  @line_number += 1
163
150
  @last_time = Time.now
164
151
  end
@@ -172,25 +159,24 @@ module Fluent
172
159
  def initialize(path, &receive_lines)
173
160
  super path, INTERVAL
174
161
  @path = path
175
- @io = File.open(path)
176
- @pos = 0
162
+ @io = File.open(path, File::NONBLOCK | File::TRUNC)
177
163
  @receive_lines = receive_lines
164
+ @partial = ""
178
165
  end
179
166
 
180
167
  def on_change(prev, cur)
181
- return if cur.size < @pos
182
-
183
- buffer = @io.read(cur.size - @pos)
184
- @pos = cur.size
185
- lines = []
186
- while line = buffer.slice!(/.*?\n/m)
187
- lines << line.chomp
188
- end
168
+ buffer = @io.read_nonblock(65536)
169
+ lines = buffer.split("\n").map(&:chomp)
170
+ return if lines.empty?
171
+ lines[0] = @partial + lines.first unless @partial.empty?
172
+ @partial = buffer.end_with?("\n") ? "" : lines.pop
189
173
  @receive_lines.call(lines)
174
+ rescue IO::WaitReadable
175
+ # will be readable on next event
190
176
  end
191
177
  end
192
178
 
193
- class TimerWatcher < Coolio::TimerWatcher
179
+ class TimerWatcher < Cool.io::TimerWatcher
194
180
  def initialize(interval, repeat, &check_dstat)
195
181
  @check_dstat = check_dstat
196
182
  super(interval, repeat)
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-dstat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shunsuke Mikami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-15 00:00:00.000000000 Z
11
+ date: 2016-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: fluent-mixin-rewrite-tag-name
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: fluentd
29
15
  requirement: !ruby/object:Gem::Requirement