fluent-plugin-dstat 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fluent-plugin-dstat"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shunsuke Mikami"]
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "fluent-plugin-dstat.gemspec",
27
- "lib/fluent-plugin-dstat.rb",
27
+ "lib/fluent/plugin/in_dstat.rb",
28
28
  "test/helper.rb",
29
29
  "test/plugin/test_in_dstat.rb"
30
30
  ]
@@ -0,0 +1,82 @@
1
+ module Fluent
2
+
3
+
4
+ class DstatInput < Input
5
+ Plugin.register_input('dstat', self)
6
+
7
+ def initialize
8
+ super
9
+ @hostname = `hostname -s`.chomp!
10
+ @line_number = 0
11
+ @first_keys = []
12
+ end
13
+
14
+ config_param :tag, :string
15
+ config_param :option, :string, :default => "-fcdnm 1"
16
+
17
+ def configure(conf)
18
+ super
19
+ @command = "dstat #{@option}"
20
+ end
21
+
22
+ def start
23
+ @io = IO.popen(@command, "r")
24
+ @pid = @io.pid
25
+ @thread = Thread.new(&method(:run))
26
+ end
27
+
28
+ def shutdown
29
+ Process.kill(:TERM, @pid)
30
+ if @thread.join(60) # TODO wait time
31
+ return
32
+ end
33
+ Process.kill(:KILL, @pid)
34
+ @thread.join
35
+ end
36
+
37
+ def run
38
+ @io.each_line(&method(:each_line))
39
+ end
40
+
41
+ private
42
+ def each_line(line)
43
+ begin
44
+ line.chomp!
45
+ line.gsub!(/\e\[7l/, "")
46
+
47
+ case @line_number
48
+ when 0
49
+ @first_keys = line.split(" ").map {|i| i.gsub(/^-+|-+$/, "") }
50
+ when 1
51
+ @second_keys = Array.new( @first_keys.length, nil)
52
+ line.split(/[:\|]/).each_with_index do |i, index|
53
+ keys = i.split(" ")
54
+ @second_keys[index] = keys
55
+ end
56
+ else
57
+ hash = Hash.new()
58
+ line.split(/[:\|]/).each_with_index do |i, index|
59
+ keys = i.split(" ")
60
+ value_hash = Hash.new()
61
+ @second_keys[index].each_with_index do |j, second_index|
62
+ value_hash[j] = keys[second_index]
63
+ end
64
+ hash[@first_keys[index]] = value_hash
65
+ end
66
+ record = {
67
+ 'hostname' => @hostname,
68
+ 'dstat' => hash
69
+ }
70
+ Engine.emit(@tag, Engine.now, record)
71
+ end
72
+ @line_number += 1
73
+
74
+ rescue
75
+ $log.error "exec failed to emit", :error=>$!, :line=>line
76
+ $log.warn_backtrace $!.backtrace
77
+ end
78
+ end
79
+ end
80
+
81
+
82
+ end
@@ -1,5 +1,4 @@
1
- require 'fluent/test'
2
- require 'net/http'
1
+ require 'helper'
3
2
 
4
3
  class DstatInputTest < Test::Unit::TestCase
5
4
  def setup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-dstat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
16
- requirement: &21572860 !ruby/object:Gem::Requirement
16
+ requirement: &15374440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.10.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21572860
24
+ version_requirements: *15374440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &21572260 !ruby/object:Gem::Requirement
27
+ requirement: &15373460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *21572260
35
+ version_requirements: *15373460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &21571660 !ruby/object:Gem::Requirement
38
+ requirement: &15342660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *21571660
46
+ version_requirements: *15342660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &21571060 !ruby/object:Gem::Requirement
49
+ requirement: &15341480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *21571060
57
+ version_requirements: *15341480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &21570500 !ruby/object:Gem::Requirement
60
+ requirement: &15340500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *21570500
68
+ version_requirements: *15340500
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &21570020 !ruby/object:Gem::Requirement
71
+ requirement: &15339620 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *21570020
79
+ version_requirements: *15339620
80
80
  description:
81
81
  email: shun0102@gmail.com
82
82
  executables: []
@@ -93,7 +93,7 @@ files:
93
93
  - Rakefile
94
94
  - VERSION
95
95
  - fluent-plugin-dstat.gemspec
96
- - lib/fluent-plugin-dstat.rb
96
+ - lib/fluent/plugin/in_dstat.rb
97
97
  - test/helper.rb
98
98
  - test/plugin/test_in_dstat.rb
99
99
  homepage: http://github.com/shun0102/fluent-plugin-dstat
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  segments:
112
112
  - 0
113
- hash: -3260140895686169377
113
+ hash: -2536050256067886842
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  none: false
116
116
  requirements:
File without changes