fluent-plugin-elapsed-time 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +37 -3
- data/fluent-plugin-elapsed-time.gemspec +1 -1
- data/lib/fluent/plugin/out_elapsed_time.rb +71 -10
- data/spec/out_elapsed_time_spec.rb +35 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d14cf6319e26776194fbb0919e67088cd7ea95b4
|
4
|
+
data.tar.gz: 3ddedf3e28e320fafcff40ceab676373afcbaa57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2cdc21c833167dfdbcb966eb94985dc368f55887bda1b19a28711b400fdfe3a840b06bf654688f1337b8baa9f74fb8bff5c960797c7365232a5e30a3afead4d
|
7
|
+
data.tar.gz: 851810c1aa907d6be79c9f54fb7cd1b41747006553979f363659b51cbf8b17162b039e700cc0f2af574a186ec71c1a49b202a2e4f4a99772e3e409d76dcc5d3c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,6 +21,7 @@ Following example measures the max and average time taken to process [fluent-plu
|
|
21
21
|
type elapsed_time
|
22
22
|
tag elapsed
|
23
23
|
interval 60
|
24
|
+
each message
|
24
25
|
<store>
|
25
26
|
type grep
|
26
27
|
exclude foobar
|
@@ -45,11 +46,15 @@ Following example measures the max and average time taken to process [fluent-plu
|
|
45
46
|
</match>
|
46
47
|
```
|
47
48
|
|
48
|
-
|
49
|
+
Output will be like
|
49
50
|
|
50
|
-
|
51
|
+
```
|
52
|
+
elapsed: {"max":1.011,"avg":0.002","num":10}
|
53
|
+
```
|
51
54
|
|
52
|
-
|
55
|
+
where `max` and `avg` are the maximum and average elapsed times, and `num` is the number of messages.
|
56
|
+
|
57
|
+
## Option Parameters
|
53
58
|
|
54
59
|
* interval
|
55
60
|
|
@@ -59,6 +64,35 @@ Following example measures the max and average time taken to process [fluent-plu
|
|
59
64
|
|
60
65
|
Measure time for each `message` or `es` (event stream). Please notice that the event stream (would be a msgpack) will be unpacked if `message` is specified, which would cause performance degradation. Default is `es`.
|
61
66
|
|
67
|
+
* tag
|
68
|
+
|
69
|
+
The output tag name. Default is `elapsed`
|
70
|
+
|
71
|
+
* add_tag_prefix
|
72
|
+
|
73
|
+
Add tag prefix for output message
|
74
|
+
|
75
|
+
* remove_tag_prefix
|
76
|
+
|
77
|
+
Remove tag prefix for output message
|
78
|
+
|
79
|
+
* remove_tag_slice *min..max*
|
80
|
+
|
81
|
+
Remove tag parts by slice function. FYI: This option behaves like `tag.split('.').slice(min..max)`.
|
82
|
+
|
83
|
+
For example,
|
84
|
+
|
85
|
+
remove_tag_slice 0..-2
|
86
|
+
|
87
|
+
changes an input tag `foo.bar.host1` to `foo.bar`.
|
88
|
+
|
89
|
+
* aggregate
|
90
|
+
|
91
|
+
Measure and emit outputs for each `tag` or `all`. Default is `all`.
|
92
|
+
|
93
|
+
`all` measures `max` and `avg` for all input messages.
|
94
|
+
`tag` measures `max` and `avg` for each tag *modified* by `add_tag_prefix`, `remove_tag_prefix`, or `remove_tag_slice`.
|
95
|
+
|
62
96
|
## ChangeLog
|
63
97
|
|
64
98
|
See [CHANGELOG.md](CHANGELOG.md) for details.
|
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = "fluent-plugin-elapsed-time"
|
6
|
-
gem.version = "0.0.
|
6
|
+
gem.version = "0.0.3"
|
7
7
|
gem.authors = ["Naotoshi Seo"]
|
8
8
|
gem.email = "sonots@gmail.com"
|
9
9
|
gem.homepage = "https://github.com/sonots/fluent-plugin-elapsed-time"
|
@@ -3,6 +3,10 @@ module Fluent
|
|
3
3
|
Plugin.register_output('elapsed_time', self)
|
4
4
|
|
5
5
|
config_param :tag, :string, :default => 'elapsed'
|
6
|
+
config_param :add_tag_prefix, :string, :default => nil
|
7
|
+
config_param :remove_tag_prefix, :string, :default => nil
|
8
|
+
config_param :remove_tag_slice, :string, :default => nil
|
9
|
+
config_param :aggregate, :string, :default => 'all'
|
6
10
|
config_param :interval, :time, :default => 60
|
7
11
|
config_param :each, :default => :es do |val|
|
8
12
|
case val.downcase
|
@@ -18,10 +22,15 @@ module Fluent
|
|
18
22
|
def initialize
|
19
23
|
super
|
20
24
|
@outputs = []
|
21
|
-
@elapsed =
|
25
|
+
@elapsed = {}
|
22
26
|
end
|
23
27
|
|
24
|
-
|
28
|
+
# for test
|
29
|
+
attr_reader :outputs
|
30
|
+
|
31
|
+
def elapsed(tag = :all)
|
32
|
+
@elapsed[tag] ||= []
|
33
|
+
end
|
25
34
|
|
26
35
|
def configure(conf)
|
27
36
|
super
|
@@ -39,6 +48,50 @@ module Fluent
|
|
39
48
|
@outputs << output
|
40
49
|
}
|
41
50
|
|
51
|
+
case @aggregate
|
52
|
+
when 'all'
|
53
|
+
raise ConfigError, "out_elapsed_time: `tag` must be specified with aggregate all" if @tag.nil?
|
54
|
+
when 'tag'
|
55
|
+
raise ConfigError, "out_elapsed_time: `add_tag_prefix` or `remove_tag_prefix` must be specified with aggregate tag" if @add_tag_prefix.nil? and @remove_tag_prefix.nil?
|
56
|
+
else
|
57
|
+
raise ConfigError, "out_elapsed_time: aggregate allows `tag` or `all`"
|
58
|
+
end
|
59
|
+
|
60
|
+
@tag_slice_proc =
|
61
|
+
if @remove_tag_slice
|
62
|
+
lindex, rindex = @remove_tag_slice.split('..', 2)
|
63
|
+
if lindex.nil? or rindex.nil? or lindex !~ /^-?\d+$/ or rindex !~ /^-?\d+$/
|
64
|
+
raise Fluent::ConfigError, "out_elapsed_time: remove_tag_slice must be formatted like [num]..[num]"
|
65
|
+
end
|
66
|
+
l, r = lindex.to_i, rindex.to_i
|
67
|
+
Proc.new {|tag| (tags = tag.split('.')[l..r]).nil? ? "" : tags.join('.') }
|
68
|
+
else
|
69
|
+
Proc.new {|tag| tag }
|
70
|
+
end
|
71
|
+
|
72
|
+
@tag_prefix = "#{@add_tag_prefix}." if @add_tag_prefix
|
73
|
+
@tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix
|
74
|
+
@tag_proc =
|
75
|
+
if @tag_prefix and @tag_prefix_match
|
76
|
+
Proc.new {|tag| "#{@tag_prefix}#{lstrip(@tag_slice_proc.call(tag), @tag_prefix_match)}" }
|
77
|
+
elsif @tag_prefix_match
|
78
|
+
Proc.new {|tag| lstrip(@tag_slice_proc.call(tag), @tag_prefix_match) }
|
79
|
+
elsif @tag_prefix
|
80
|
+
Proc.new {|tag| "#{@tag_prefix}#{@tag_slice_proc.call(tag)}" }
|
81
|
+
elsif @tag
|
82
|
+
Proc.new {|tag| @tag }
|
83
|
+
else
|
84
|
+
Proc.new {|tag| @tag_slice_proc.call(tag) }
|
85
|
+
end
|
86
|
+
|
87
|
+
@push_elapsed_proc =
|
88
|
+
case @aggregate
|
89
|
+
when 'all'
|
90
|
+
Proc.new {|tag, elapsed_time| elapsed(:all) << elapsed_time }
|
91
|
+
when 'tag'
|
92
|
+
Proc.new {|tag, elapsed_time| elapsed(tag) << elapsed_time }
|
93
|
+
end
|
94
|
+
|
42
95
|
@emit_proc =
|
43
96
|
if @each == :message
|
44
97
|
chain = NullOutputChain.instance
|
@@ -47,7 +100,8 @@ module Fluent
|
|
47
100
|
es.each do |time, record|
|
48
101
|
@outputs.each {|output| output.emit(tag, OneEventStream.new(time, record), chain) }
|
49
102
|
finish = Time.now
|
50
|
-
|
103
|
+
elapsed = (finish - start).to_f
|
104
|
+
@push_elapsed_proc.call(@tag_proc.call(tag), elapsed)
|
51
105
|
start = finish
|
52
106
|
end
|
53
107
|
}
|
@@ -56,7 +110,8 @@ module Fluent
|
|
56
110
|
Proc.new {|tag, es|
|
57
111
|
t = Time.now
|
58
112
|
@outputs.each {|output| output.emit(tag, es, chain) }
|
59
|
-
|
113
|
+
elapsed = (Time.now - t).to_f
|
114
|
+
@push_elapsed_proc.call(@tag_proc.call(tag), elapsed)
|
60
115
|
}
|
61
116
|
end
|
62
117
|
end
|
@@ -88,12 +143,14 @@ module Fluent
|
|
88
143
|
end
|
89
144
|
|
90
145
|
def flush_emit
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
146
|
+
elapseds, @elapsed = @elapsed, {}
|
147
|
+
elapseds.each do |tag, elapsed|
|
148
|
+
unless elapsed.empty?
|
149
|
+
max = elapsed.max
|
150
|
+
num = elapsed.size
|
151
|
+
avg = elapsed.map(&:to_f).inject(:+) / num.to_f
|
152
|
+
Engine.emit(tag, Engine.now, {"max" => max, "avg" => avg, "num" => num})
|
153
|
+
end
|
97
154
|
end
|
98
155
|
end
|
99
156
|
|
@@ -101,5 +158,9 @@ module Fluent
|
|
101
158
|
@emit_proc.call(tag, es)
|
102
159
|
chain.next
|
103
160
|
end
|
161
|
+
|
162
|
+
def lstrip(string, substring)
|
163
|
+
string.index(substring) == 0 ? string[substring.size..-1] : string
|
164
|
+
end
|
104
165
|
end
|
105
166
|
end
|
@@ -86,5 +86,40 @@ describe Fluent::ElapsedTimeOutput do
|
|
86
86
|
driver.instance.elapsed.size.should == 4
|
87
87
|
}
|
88
88
|
end
|
89
|
+
|
90
|
+
context 'each message with aggregate tag' do
|
91
|
+
let(:config) { CONFIG + %[each message\naggregate tag\nadd_tag_prefix elapsed]}
|
92
|
+
before do
|
93
|
+
Fluent::Engine.stub(:now).and_return(time)
|
94
|
+
end
|
95
|
+
it {
|
96
|
+
driver.run { messages.each {|message| driver.emit({'message' => message}, time) } }
|
97
|
+
driver.instance.elapsed("elapsed.#{tag}").size.should == 4
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'each es with aggregate tag' do
|
102
|
+
let(:config) { CONFIG + %[each es\naggregate tag\nadd_tag_prefix elapsed]}
|
103
|
+
before do
|
104
|
+
Fluent::Engine.stub(:now).and_return(time)
|
105
|
+
end
|
106
|
+
it {
|
107
|
+
driver.run { messages.each {|message| driver.emit({'message' => message}, time) } }
|
108
|
+
driver.instance.elapsed("elapsed.#{tag}").size.should == 4
|
109
|
+
driver.instance.flush_emit
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'remove_tag_slice' do
|
114
|
+
let(:config) { CONFIG + %[remove_tag_slice 0..-2\naggregate tag\nadd_tag_prefix elapsed]}
|
115
|
+
before do
|
116
|
+
Fluent::Engine.stub(:now).and_return(time)
|
117
|
+
end
|
118
|
+
let(:expected_tag) { tag.split('.')[0..-2].join('.') }
|
119
|
+
it {
|
120
|
+
driver.run { messages.each {|message| driver.emit({'message' => message}, time) } }
|
121
|
+
driver.instance.elapsed("elapsed.#{expected_tag}").size.should == 4
|
122
|
+
}
|
123
|
+
end
|
89
124
|
end
|
90
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elapsed-time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|