fluent-plugin-calc 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ef459d57b1a570eb06400f3eb8e6a4b54ed0323
4
- data.tar.gz: 3f075999d044512d5504897e237dd7e8a07f57e6
3
+ metadata.gz: a1c071f135ee347fbda42cabebcf97145738e861
4
+ data.tar.gz: d96f235f6f89144c8c576be0a8502034355c6147
5
5
  SHA512:
6
- metadata.gz: 94465d66d28c3ec8596b94c19e9da14c6ecd2624262dc9ce27038b19ca8ee50c529242bba14be09aba95ba7545627da935dd5e4fd6d07f7af44af3f8fefac1c1
7
- data.tar.gz: 76c2f2d778128c2287111b086290c14f7cf05df08eac3f7d7aa39717061b0c9408749ddcf6103a58df9b6c3a641898135cb57d87c757a8ce4f568d2114364d5d
6
+ metadata.gz: 10600118061e558c871707bff0c6d24c55aa2c6b3dea62c176a5ac0f2e317dc2d1dd116bf306c2f4a806e26510105a2b6ce5d4969b4ff349e1152b4e885a4019
7
+ data.tar.gz: 2ddf8699037167a5bd72aef1a3489d73487bbb75c1befd80c77cf2be0d60e3c70468eb45fbdba1efa6f52417926c69bd45bd117b1881eb48b610edd3af5aec7f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.0.2 (2013/05/06)
2
+
3
+ Bugfixes:
4
+
5
+ - Fix so that @avg can be an option
6
+
1
7
  ## 0.0.1 (2013/05/05)
2
8
 
3
9
  First version
10
+
data/README.md CHANGED
@@ -7,7 +7,6 @@ Fluentd plugin to calc messages.
7
7
  <match foo.**>
8
8
  type calc
9
9
  interval 5s
10
- aggragate tag
11
10
  add_tag_prefix calc
12
11
 
13
12
  sum .*_count$
@@ -18,18 +17,18 @@ Fluentd plugin to calc messages.
18
17
 
19
18
  Assuming following inputs are coming:
20
19
 
21
- foo.bar: {"4xx_count":1,"5xx_count":2","reqtime_max":12083,"reqtime_min":10,reqtime_avg":240.46}
22
- foo.bar: {"4xx_count":4,"5xx_count":2","reqtime_max":24831,"reqtime_min":82,reqtime_avg":300.46}
20
+ foo.bar: {"4xx_count":1,"5xx_count":2","reqtime_max":12083,"reqtime_min":10,"reqtime_avg":240.46}
21
+ foo.bar: {"4xx_count":4,"5xx_count":2","reqtime_max":24831,"reqtime_min":82,"reqtime_avg":300.46}
23
22
 
24
23
  then output bocomes as belows:
25
24
 
26
- foo.bar: {"4xx_count":5,"5xx_count":4","reqtime_max":24831,"reqtime_min":82,reqtime_avg":270.46}
25
+ calc.foo.bar: {"4xx_count":5,"5xx_count":4","reqtime_max":24831,"reqtime_min":82,"reqtime_avg":270.46}
27
26
 
28
27
  ## Parameters
29
28
 
30
- - aggragate
31
-
32
- Calculate by each `tag` or `all`. The default value is `tag`.
29
+ - sum, min, max, avg
30
+
31
+ Calculation. Specify input keys by a regular expression
33
32
 
34
33
  - interval
35
34
 
@@ -37,15 +36,15 @@ then output bocomes as belows:
37
36
 
38
37
  - tag
39
38
 
40
- The output tag name
39
+ The output tag name. Required for aggregate `all`.
41
40
 
42
41
  - add_tag_prefix
43
42
 
44
- Add tag prefix for output message
43
+ Add tag prefix for output message.
45
44
 
46
- - sum, min, max, avg
47
-
48
- Calculation. Specify input keys by a regular expression
45
+ - aggragate
46
+
47
+ Calculate by each `tag` or `all`. The default value is `tag`.
49
48
 
50
49
  ## ChangeLog
51
50
 
@@ -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.1"
6
+ s.version = "0.0.2"
7
7
  s.authors = ["Naotoshi SEO"]
8
8
  s.email = ["sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/sonots/fluent-plugin-calc"
@@ -121,7 +121,7 @@ class Fluent::CalcOutput < Fluent::Output
121
121
  def generate_output(count, matches)
122
122
  output = matches.dup
123
123
  output.keys.each do |key|
124
- if @avg.match(key)
124
+ if @avg and @avg.match(key)
125
125
  output[key] = matches[key] / count.to_f # compute avg
126
126
  end
127
127
  end
@@ -1,11 +1,16 @@
1
1
  # encoding: UTF-8
2
2
  require_relative 'spec_helper'
3
3
 
4
+ class Fluent::Test::OutputTestDriver
5
+ def emit_with_tag(record, time=Time.now, tag = nil)
6
+ @tag = tag if tag
7
+ emit(record, time)
8
+ end
9
+ end
10
+
4
11
  describe Fluent::CalcOutput do
5
12
  before { Fluent::Test.setup }
6
- CONFIG = %[
7
- input_key message
8
- ]
13
+ CONFIG = %[]
9
14
  let(:tag) { 'foo.bar' }
10
15
  let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::CalcOutput, tag).configure(config) }
11
16
 
@@ -14,7 +19,7 @@ describe Fluent::CalcOutput do
14
19
  context 'invalid aggregate' do
15
20
  let(:config) do
16
21
  CONFIG + %[
17
- aggregate foo
22
+ aggregate foo
18
23
  ]
19
24
  end
20
25
  it { expect { driver }.to raise_error(Fluent::ConfigError) }
@@ -23,7 +28,7 @@ describe Fluent::CalcOutput do
23
28
  context 'no tag for aggregate all' do
24
29
  let(:config) do
25
30
  CONFIG + %[
26
- aggregate all
31
+ aggregate all
27
32
  ]
28
33
  end
29
34
  it { expect { driver }.to raise_error(Fluent::ConfigError) }
@@ -64,6 +69,7 @@ describe Fluent::CalcOutput do
64
69
  let(:messages) do
65
70
  [
66
71
  {"4xx_count"=>1,"5xx_count"=>2,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3},
72
+ {">4sec_count"=>1},
67
73
  {"4xx_count"=>2,"5xx_count"=>2,"reqtime_max"=>5,"reqtime_min"=>2,"reqtime_avg"=>2},
68
74
  {"4xx_count"=>3,"5xx_count"=>2,"reqtime_max"=>1,"reqtime_min"=>3,"reqtime_avg"=>4},
69
75
  ]
@@ -121,24 +127,49 @@ describe Fluent::CalcOutput do
121
127
  it { emit }
122
128
  end
123
129
 
124
- context 'aggregate all' do
125
- let(:config) do
126
- CONFIG + %[
130
+ context 'aggregate' do
131
+ let(:emit) do
132
+ driver.run { messages.each {|message| driver.emit_with_tag(message, time, 'foo.bar') } }
133
+ driver.run { messages.each {|message| driver.emit_with_tag(message, time, 'foo.bar2') } }
134
+ driver.instance.flush_emit(0)
135
+ end
136
+
137
+ context 'aggregate all' do
138
+ let(:config) do
139
+ CONFIG + %[
127
140
  aggregate all
128
141
  tag foo
129
142
  sum _count$
130
- max _max$
131
- min _min$
132
- avg _avg$
133
143
  ]
144
+ end
145
+ before do
146
+ Fluent::Engine.stub(:now).and_return(time)
147
+ Fluent::Engine.should_receive(:emit).with("foo", time, {
148
+ "4xx_count"=>12,"5xx_count"=>12,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0
149
+ })
150
+ end
151
+ it { emit }
134
152
  end
135
- before do
136
- Fluent::Engine.stub(:now).and_return(time)
137
- Fluent::Engine.should_receive(:emit).with("foo", time, {
138
- "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0
139
- })
153
+
154
+ context 'aggregate tag' do
155
+ let(:config) do
156
+ CONFIG + %[
157
+ aggregate tag
158
+ add_tag_prefix calc
159
+ sum _count$
160
+ ]
161
+ end
162
+ before do
163
+ Fluent::Engine.stub(:now).and_return(time)
164
+ Fluent::Engine.should_receive(:emit).with("calc.foo.bar", time, {
165
+ "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0
166
+ })
167
+ Fluent::Engine.should_receive(:emit).with("calc.foo.bar2", time, {
168
+ "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0
169
+ })
170
+ end
171
+ it { emit }
140
172
  end
141
- it { emit }
142
173
  end
143
174
  end
144
175
  end
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.1
4
+ version: 0.0.2
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-05-05 00:00:00.000000000 Z
11
+ date: 2013-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd