fluent-plugin-dstat 0.0.3 → 0.1.0
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.
- data/README.rdoc +34 -10
- data/VERSION +1 -1
- data/fluent-plugin-dstat.gemspec +2 -2
- data/lib/fluent/plugin/in_dstat.rb +58 -13
- data/test/plugin/test_in_dstat.rb +30 -3
- metadata +15 -15
data/README.rdoc
CHANGED
@@ -1,16 +1,40 @@
|
|
1
|
-
=
|
1
|
+
= Dstat plugin for Fluent
|
2
2
|
|
3
3
|
Description goes here.
|
4
4
|
|
5
|
-
==
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
== What's Dstat?
|
6
|
+
|
7
|
+
Dstat is a versatile replacement for vmstat, iostat, netstat and ifstat.
|
8
|
+
If you need more detail, see here[http://dag.wieers.com/home-made/dstat]
|
9
|
+
This plugin use Dstat, so you need to install Dstat before using this plugin.
|
10
|
+
|
11
|
+
== Configuration
|
12
|
+
|
13
|
+
<source>
|
14
|
+
type dstat
|
15
|
+
tag dstat
|
16
|
+
option -c 3
|
17
|
+
</source>
|
18
|
+
|
19
|
+
* option:option for dstat command(default: -fcdnm 1)
|
20
|
+
|
21
|
+
== Output Format
|
22
|
+
|
23
|
+
When you use option -c, you get structured output data like below.
|
24
|
+
|
25
|
+
{
|
26
|
+
"hostname":"tsukuba000",
|
27
|
+
"dstat":{"total-cpu-usage":{"usr":"0",
|
28
|
+
"sys":"0",
|
29
|
+
"idl":"100",
|
30
|
+
"wai":"0",
|
31
|
+
"hiq":"0",
|
32
|
+
"siq":"0"}}
|
33
|
+
}
|
34
|
+
|
35
|
+
== Supported options
|
36
|
+
|
37
|
+
aio, cpu, cpu24, disk, epoch, fs, int, int24, io, ipc, load, lock, mem, net, page, page24, proc, raw, socket, swap, swapold, sys, tcp, udp, unix, vm, disk-tps, disk-util, dstat-cpu, dstat-ctxt, dstat-mem, freespace, top-bio, top-childwait, top-cpu,top-io, top-mem, top-oom, utmp, top-io -fc
|
14
38
|
|
15
39
|
== Copyright
|
16
40
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/fluent-plugin-dstat.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fluent-plugin-dstat"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
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"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2012-01-12"
|
13
13
|
s.email = "shun0102@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -1,7 +1,23 @@
|
|
1
1
|
module Fluent
|
2
2
|
|
3
|
-
|
4
3
|
class DstatInput < Input
|
4
|
+
|
5
|
+
def split_second_key(str)
|
6
|
+
result = []
|
7
|
+
while (str)
|
8
|
+
index = /[^ ] / =~ str
|
9
|
+
if index
|
10
|
+
result << str[0..index]
|
11
|
+
else
|
12
|
+
result << str unless str == " "
|
13
|
+
return result
|
14
|
+
end
|
15
|
+
str = str[(index + 1)..-1]
|
16
|
+
end
|
17
|
+
|
18
|
+
return result
|
19
|
+
end
|
20
|
+
|
5
21
|
Plugin.register_input('dstat', self)
|
6
22
|
|
7
23
|
def initialize
|
@@ -9,14 +25,16 @@ class DstatInput < Input
|
|
9
25
|
@hostname = `hostname -s`.chomp!
|
10
26
|
@line_number = 0
|
11
27
|
@first_keys = []
|
28
|
+
@second_keys = []
|
12
29
|
end
|
13
30
|
|
14
31
|
config_param :tag, :string
|
15
|
-
config_param :option, :string, :default => "-fcdnm
|
32
|
+
config_param :option, :string, :default => "-fcdnm"
|
33
|
+
config_param :delay, :integer, :default => 1
|
16
34
|
|
17
35
|
def configure(conf)
|
18
36
|
super
|
19
|
-
@command = "dstat #{@option}"
|
37
|
+
@command = "dstat #{@option} #{@delay}"
|
20
38
|
end
|
21
39
|
|
22
40
|
def start
|
@@ -46,23 +64,50 @@ class DstatInput < Input
|
|
46
64
|
|
47
65
|
case @line_number
|
48
66
|
when 0
|
49
|
-
@first_keys = line.split(" ")
|
67
|
+
@first_keys = line.split(" ")
|
50
68
|
when 1
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
69
|
+
index = 0
|
70
|
+
@first_keys.each do |i|
|
71
|
+
@second_keys << line[index..(index + i.length - 1)]
|
72
|
+
index += i.length + 1
|
55
73
|
end
|
56
74
|
else
|
57
75
|
hash = Hash.new()
|
58
|
-
|
59
|
-
|
76
|
+
values = []
|
77
|
+
index = 0
|
78
|
+
@first_keys.each do |i|
|
79
|
+
values << line[index..(index + i.length - 1)]
|
80
|
+
index += i.length + 1
|
81
|
+
end
|
82
|
+
|
83
|
+
@first_keys.each_with_index do |i, index|
|
60
84
|
value_hash = Hash.new()
|
61
|
-
|
62
|
-
|
85
|
+
first = i.gsub(/^-+|-+$/, "")
|
86
|
+
length = i.length
|
87
|
+
|
88
|
+
if first == "most-expensive"
|
89
|
+
s_key = @second_keys[index].gsub(/^\s+|\s+$/, "")
|
90
|
+
value_hash[s_key] = values[index]
|
91
|
+
else
|
92
|
+
keys = split_second_key(@second_keys[index])
|
93
|
+
second_index = 0
|
94
|
+
|
95
|
+
keys.each do |i|
|
96
|
+
next_index = second_index + i.length - 1
|
97
|
+
value = values[index][second_index..next_index]
|
98
|
+
second_index += i.length + 1
|
99
|
+
value = value.gsub(/^\s+|\s+$/, "") if value
|
100
|
+
value_hash[i.gsub(/^\s+|\s+$/, "")] = value
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
if hash[first].nil?
|
105
|
+
hash[first] = value_hash
|
106
|
+
else
|
107
|
+
hash[first] = hash[first].merge(value_hash)
|
63
108
|
end
|
64
|
-
hash[@first_keys[index]] = value_hash
|
65
109
|
end
|
110
|
+
|
66
111
|
record = {
|
67
112
|
'hostname' => @hostname,
|
68
113
|
'dstat' => hash
|
@@ -5,9 +5,18 @@ class DstatInputTest < Test::Unit::TestCase
|
|
5
5
|
Fluent::Test.setup
|
6
6
|
end
|
7
7
|
|
8
|
+
OPTIONS = ["aio", "cpu", "cpu24", "disk",
|
9
|
+
"epoch", "fs", "int", "int24", "io", "ipc", "load", "lock",
|
10
|
+
"mem", "net", "page", "page24", "proc", "raw", "socket",
|
11
|
+
"swap", "swapold", "sys", "tcp", "udp", "unix", "vm",
|
12
|
+
"disk-tps", "disk-util", "dstat-cpu", "dstat-ctxt", "dstat-mem", "freespace",
|
13
|
+
"top-bio", "top-childwait", "top-cpu","top-io",
|
14
|
+
"top-mem", "top-oom", "utmp", "top-io -fc"]
|
15
|
+
|
8
16
|
CONFIG = %[
|
9
17
|
tag dstat
|
10
|
-
option -
|
18
|
+
option --aio -cpu
|
19
|
+
delay 1
|
11
20
|
]
|
12
21
|
|
13
22
|
def create_driver(conf=CONFIG)
|
@@ -16,17 +25,35 @@ class DstatInputTest < Test::Unit::TestCase
|
|
16
25
|
|
17
26
|
def test_configure
|
18
27
|
d = create_driver
|
19
|
-
assert_equal
|
28
|
+
assert_equal 1, d.instance.delay
|
20
29
|
end
|
21
30
|
|
22
31
|
def test_emit
|
23
|
-
|
32
|
+
|
33
|
+
OPTIONS.each do |op|
|
34
|
+
#emit_with_conf(CONFIG)
|
35
|
+
conf = "tag dstat\n option --#{op}\n delay 1"
|
36
|
+
emit_with_conf(conf)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def emit_with_conf(conf)
|
42
|
+
d = create_driver(conf)
|
24
43
|
|
25
44
|
d.run do
|
26
45
|
sleep 2
|
27
46
|
end
|
28
47
|
|
48
|
+
length = `dstat #{d.instance.option} #{d.instance.delay} 1`.split("\n")[0].split("\s").length
|
49
|
+
|
29
50
|
emits = d.emits
|
30
51
|
assert_equal true, emits.length > 0
|
52
|
+
assert_equal length, emits[0][2]['dstat'].length
|
53
|
+
|
54
|
+
puts "--- #{d.instance.option} ---"
|
55
|
+
puts emits[0][2]
|
56
|
+
puts "--- end ---"
|
31
57
|
end
|
58
|
+
|
32
59
|
end
|
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
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-12 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
16
|
-
requirement: &
|
16
|
+
requirement: &22315940 !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: *
|
24
|
+
version_requirements: *22315940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &22315460 !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: *
|
35
|
+
version_requirements: *22315460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda
|
38
|
-
requirement: &
|
38
|
+
requirement: &22314980 !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: *
|
46
|
+
version_requirements: *22314980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &22314500 !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: *
|
57
|
+
version_requirements: *22314500
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &22314020 !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: *
|
68
|
+
version_requirements: *22314020
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
requirement: &
|
71
|
+
requirement: &22313540 !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: *
|
79
|
+
version_requirements: *22313540
|
80
80
|
description:
|
81
81
|
email: shun0102@gmail.com
|
82
82
|
executables: []
|
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
segments:
|
112
112
|
- 0
|
113
|
-
hash:
|
113
|
+
hash: 3115706696286106192
|
114
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
115
|
none: false
|
116
116
|
requirements:
|