fluent-plugin-calc 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +9 -3
- data/fluent-plugin-calc.gemspec +1 -1
- data/lib/fluent/plugin/out_calc.rb +22 -2
- data/spec/out_calc_spec.rb +18 -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: 3c4e47d56f27cba7e3e04f0738eb6434456ce824
|
4
|
+
data.tar.gz: e759f302614709da9350bd0f59a748cc7ab6d724
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9701abea3da09295a09a02fd8867fc882644ef9f980ea2896ea95e953945f8413790494fb784cfd19294f451e1ef0300961e3298619f864629371e20fefffee
|
7
|
+
data.tar.gz: 1a1d71d9497dc2bfb394eb1cc58c47daed5dd3b4aab686a7388a6ad22218dcba23513d8c0bf41eb5bb09df165373a05138afa0b7682ebf7212d3699c9191a919
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Simple fluentd plugin to calculate messages.
|
|
4
4
|
|
5
5
|
## Configuration
|
6
6
|
|
7
|
-
|
7
|
+
### Example 1
|
8
8
|
|
9
9
|
sum for xxx_count, max for xxx_max, min for xxx_min, avg for xxx_avg
|
10
10
|
|
@@ -28,7 +28,7 @@ then output bocomes as belows:
|
|
28
28
|
|
29
29
|
calc.foo.bar: {"4xx_count":5,"5xx_count":4","reqtime_max":24831,"reqtime_min":10,"reqtime_avg":270.46}
|
30
30
|
|
31
|
-
|
31
|
+
### Example 2
|
32
32
|
|
33
33
|
sum, max, min, avg for the same key
|
34
34
|
|
@@ -60,7 +60,13 @@ then output bocomes as belows:
|
|
60
60
|
|
61
61
|
- sum, min, max, avg
|
62
62
|
|
63
|
-
|
63
|
+
Target of calculation. Specify input keys by a regular expression
|
64
|
+
|
65
|
+
- sum\_keys, min\_keys, max\_keys, avg\_keys
|
66
|
+
|
67
|
+
Target of calculation. Specify input keys by a string separated by , (comma) such as
|
68
|
+
|
69
|
+
sum_keys 4xx_count,5xx_count
|
64
70
|
|
65
71
|
- sum\_suffix, min\_suffix, max\_suffix, avg\_suffix
|
66
72
|
|
data/fluent-plugin-calc.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-calc"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.5"
|
7
7
|
s.authors = ["Naotoshi SEO"]
|
8
8
|
s.email = ["sonots@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-calc"
|
@@ -11,6 +11,10 @@ class Fluent::CalcOutput < Fluent::Output
|
|
11
11
|
config_param :max, :string, :default => nil
|
12
12
|
config_param :min, :string, :default => nil
|
13
13
|
config_param :avg, :string, :default => nil
|
14
|
+
config_param :sum_keys, :string, :default => nil
|
15
|
+
config_param :max_keys, :string, :default => nil
|
16
|
+
config_param :min_keys, :string, :default => nil
|
17
|
+
config_param :avg_keys, :string, :default => nil
|
14
18
|
config_param :sum_suffix, :string, :default => ""
|
15
19
|
config_param :max_suffix, :string, :default => ""
|
16
20
|
config_param :min_suffix, :string, :default => ""
|
@@ -35,6 +39,10 @@ class Fluent::CalcOutput < Fluent::Output
|
|
35
39
|
@max = Regexp.new(@max) if @max
|
36
40
|
@min = Regexp.new(@min) if @min
|
37
41
|
@avg = Regexp.new(@avg) if @avg
|
42
|
+
@sum_keys = @sum_keys ? @sum_keys.split(',') : []
|
43
|
+
@max_keys = @max_keys ? @max_keys.split(',') : []
|
44
|
+
@min_keys = @min_keys ? @min_keys.split(',') : []
|
45
|
+
@avg_keys = @avg_keys ? @avg_keys.split(',') : []
|
38
46
|
|
39
47
|
unless ['tag', 'all'].include?(@aggregate)
|
40
48
|
raise Fluent::ConfigError, "aggregate allows tag/all"
|
@@ -70,6 +78,18 @@ class Fluent::CalcOutput < Fluent::Output
|
|
70
78
|
# calc
|
71
79
|
count = 0; matches = { :sum => {}, :max => {}, :min => {}, :avg => {} }
|
72
80
|
es.each do |time, record|
|
81
|
+
@sum_keys.each do |key|
|
82
|
+
matches[:sum][key] = sum(matches[:sum][key], record[key])
|
83
|
+
end
|
84
|
+
@max_keys.each do |key|
|
85
|
+
matches[:max][key] = max(matches[:max][key], record[key])
|
86
|
+
end
|
87
|
+
@min_keys.each do |key|
|
88
|
+
matches[:min][key] = min(matches[:min][key], record[key])
|
89
|
+
end
|
90
|
+
@avg_keys.each do |key|
|
91
|
+
matches[:avg][key] = avg(matches[:avg][key], record[key])
|
92
|
+
end
|
73
93
|
record.keys.each do |key|
|
74
94
|
if @sum and @sum.match(key)
|
75
95
|
matches[:sum][key] = sum(matches[:sum][key], record[key])
|
@@ -83,7 +103,7 @@ class Fluent::CalcOutput < Fluent::Output
|
|
83
103
|
if @avg and @avg.match(key)
|
84
104
|
matches[:avg][key] = sum(matches[:avg][key], record[key]) # sum yet
|
85
105
|
end
|
86
|
-
end
|
106
|
+
end if @sum || @max || @min || @avg
|
87
107
|
count += 1
|
88
108
|
end
|
89
109
|
|
@@ -216,7 +236,7 @@ class Fluent::CalcOutput < Fluent::Output
|
|
216
236
|
stored[:min] == @min and
|
217
237
|
stored[:avg] == @avg
|
218
238
|
|
219
|
-
if !stored[:matches].first[1].has_key?(:max)
|
239
|
+
if !stored[:matches].empty? and !stored[:matches].first[1].has_key?(:max)
|
220
240
|
$log.warn "out_calc: stored data does not have compatibility with the current version. ignore stored data"
|
221
241
|
return
|
222
242
|
end
|
data/spec/out_calc_spec.rb
CHANGED
@@ -96,6 +96,24 @@ describe Fluent::CalcOutput do
|
|
96
96
|
it { emit }
|
97
97
|
end
|
98
98
|
|
99
|
+
context 'sum/max/min/avg_keys' do
|
100
|
+
let(:config) do
|
101
|
+
CONFIG + %[
|
102
|
+
sum_keys 4xx_count,5xx_count
|
103
|
+
max reqtime_max
|
104
|
+
min reqtime_min
|
105
|
+
avg reqtime_avg
|
106
|
+
]
|
107
|
+
end
|
108
|
+
before do
|
109
|
+
Fluent::Engine.stub(:now).and_return(time)
|
110
|
+
Fluent::Engine.should_receive(:emit).with("calc.#{tag}", time, {
|
111
|
+
"4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0
|
112
|
+
})
|
113
|
+
end
|
114
|
+
it { emit }
|
115
|
+
end
|
116
|
+
|
99
117
|
context 'sum/max/min/avg_suffix' do
|
100
118
|
let(:config) do
|
101
119
|
CONFIG + %[
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-calc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi SEO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|