fluent-plugin-datacalculator 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c362933d723f8d7de355e0d81e36b9c7116ec7b
4
+ data.tar.gz: 9be7571d4f6c1b809eda3cb5b69504b05b21c95e
5
+ SHA512:
6
+ metadata.gz: b8ad5784dea42de7e1fadead741046882e7a6be8ffa02fa3315d70cd67c2ffcb67aa58a4fe1f5f5066c48146b2a83bc5f5075760e3f7bb60c7692af13ffb49d9
7
+ data.tar.gz: cd0e9b17f3c57900b98ec0b526b0806433657cbb300110ca8033e924e83c3a60dda2086b0154e212f1af37e65f33e68ec39dfe35101531e465a00a422c5be7b4
@@ -0,0 +1,87 @@
1
+ # fluent-plugin-datacalculator
2
+ -----
3
+
4
+ Simple Calculate messages and summarize the calculated results.
5
+
6
+ * Summarize calculated results per min/hour/day
7
+ * Summarize calculated results per second (average every min/hour/day)
8
+ * Use finalizer of summarized results (e.g. average)
9
+
10
+ ## Usage
11
+
12
+ if fluentd set like that:
13
+
14
+ ```
15
+ <match payment.shop>
16
+ type datacalculator
17
+ tag result.shop
18
+ count_interval 5s
19
+ aggregate all
20
+ formulas sum = amount * price, cnt = 1, total = amount
21
+ finalizer ave = cnt > 0 ? 1.00 * sum / cnt : 0
22
+ </match>
23
+ ```
24
+
25
+ recieves bellow messages in a minute:
26
+
27
+ ```
28
+ {"area_id": 1, "mission_id":1, "amount": 3, "price": 100}
29
+ {"area_id": 2, "mission_id":2, "amount": 2, "price": 200}
30
+ {"area_id": 3, "mission_id":1, "amount": 3, "price": 100}
31
+ {"area_id": 4, "mission_id":1, "amount": 4, "price": 300}
32
+ {"area_id": 5, "mission_id":2, "amount": 5, "price": 200}
33
+ {"area_id": 1, "mission_id":1, "amount": 1, "price": 400}
34
+ {"area_id": 4, "mission_id":1, "amount": 2, "price": 200}
35
+ {"area_id": 3, "mission_id":2, "amount": 1, "price": 300}
36
+ ```
37
+
38
+ then output below:
39
+
40
+ ```
41
+ 2014-02-26 13:52:28 +0900 result.shop: {"sum":4300.0,"cnt":8,"total":21.0,"ave":537.5}
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ ### Example
47
+
48
+ ```
49
+ <match accesslog.**>
50
+ type datacalculate
51
+ unit minute
52
+ aggregate all
53
+ fomulas sum = amount * price, amounts = amount
54
+ </match>
55
+ ```
56
+
57
+ If you use finalizer, like this
58
+
59
+ ```
60
+ <match accesslog.**>
61
+ type datacalculate
62
+ unit minute
63
+ aggregate all
64
+ fomulas sum = amount * price, amounts = amount
65
+ finalizer average = amounts > 0 ? 1.0 * sum / amounts : 0
66
+ </match>
67
+ ```
68
+
69
+ Finalizer uses the summarized output, so argv in finalizer must exist in left-hand side in fomulas.
70
+
71
+ ### Options
72
+
73
+ * `count_interval`: aggregate time interval e.g. `5s`, `15m`, `3h`
74
+ * `aggregate`: if set `all` then all matched tags are aggregated. if set `tag` then each tags are aggregated separately (default `tag`).
75
+ * `input_tag_remove_prefix`: option available if you want to remove tag prefix from output field names. This option available when aggregate is set `tag`.
76
+ * `retain_key_combinations`: option available if you want to retain key combination created in previous to next interval (default `true`).
77
+ * `formulas`: define value and function comma separated. values are set in messages.
78
+ * `finalizer`: functions defined are executed aggregated phase. value are set in messages.
79
+
80
+ ## TODO
81
+
82
+ * multiple finalizer
83
+
84
+ ## Copyright
85
+
86
+ Copyright:: Copyright (c) 2012- Muddy Dixon
87
+ License:: Apache License, Version 2.0
@@ -7,6 +7,7 @@
7
7
  tag result.quest
8
8
  count_interval 5s
9
9
  aggregate keys area_id, mission_id
10
+ retain_key_combinations false
10
11
  formulas sum = amount * price, cnt = 1, total = amount
11
12
  finalizer ave = cnt > 0 ? 1.00 * sum / cnt : 0
12
13
  <unmatched>
@@ -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-datacalculator"
6
- s.version = "0.0.5"
6
+ s.version = "0.0.6"
7
7
  s.authors = ["Muddy Dixon"]
8
8
  s.email = ["muddydixon@gmail.com"]
9
9
  s.homepage = "https://github.com/muddydixon/fluent-plugin-datacalculator"
@@ -10,6 +10,7 @@ class Fluent::DataCalculatorOutput < Fluent::Output
10
10
  config_param :input_tag_remove_prefix, :string, :default => nil
11
11
  config_param :formulas, :string
12
12
  config_param :finalizer, :string, :default => nil
13
+ config_param :retain_key_combinations, :bool, :default => true
13
14
 
14
15
  attr_accessor :tick
15
16
  attr_accessor :counts
@@ -242,7 +243,11 @@ class Fluent::DataCalculatorOutput < Fluent::Output
242
243
  end
243
244
 
244
245
  def flush(step)
245
- flushed, @counts = @counts,count_initialized(@counts.keys.dup)
246
+ if @retain_key_combinations
247
+ flushed, @counts = @counts,count_initialized(@counts.keys.dup)
248
+ else
249
+ flushed, @counts = @counts,count_initialized
250
+ end
246
251
  generate_output(flushed, step)
247
252
  end
248
253
 
@@ -240,4 +240,38 @@ class DataCalculatorOutputTest < Test::Unit::TestCase
240
240
  assert_equal counts[pat], r['count']
241
241
  end
242
242
  end
243
+
244
+ def test_flush
245
+ # retain_key_combinations is true
246
+ d1 = create_driver(%[
247
+ unit minute
248
+ aggregate keys area_id, mission_id
249
+ formulas sum = amount * price, count = 1
250
+ retain_key_combinations true
251
+ ], 'test.input')
252
+ d1.run do
253
+ 60.times do
254
+ d1.emit({'area_id' => 1, 'mission_id' => 1, 'amount' => 3, 'price' => 100})
255
+ d1.emit({'area_id' => 2, 'mission_id' => 1, 'amount' => 3, 'price' => 100})
256
+ end
257
+ end
258
+ assert_equal d1.instance.flush(60).size, 2
259
+ assert_equal d1.instance.flush(60).size, 2
260
+
261
+ # retain_key_combinations is false
262
+ d2 = create_driver(%[
263
+ unit minute
264
+ aggregate keys area_id, mission_id
265
+ formulas sum = amount * price, count = 1
266
+ retain_key_combinations false
267
+ ], 'test.input')
268
+ d2.run do
269
+ 60.times do
270
+ d2.emit({'area_id' => 1, 'mission_id' => 1, 'amount' => 3, 'price' => 100})
271
+ d2.emit({'area_id' => 2, 'mission_id' => 1, 'amount' => 3, 'price' => 100})
272
+ end
273
+ end
274
+ assert_equal d2.instance.flush(60).size, 2
275
+ assert_equal d2.instance.flush(60).size, 0
276
+ end
243
277
  end
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-datacalculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Muddy Dixon
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: fluentd
16
- requirement: &2164769940 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *2164769940
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: fluentd
27
- requirement: &2164769420 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *2164769420
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  description: Output filter plugin to calculate messages that matches specified conditions
37
42
  email:
38
43
  - muddydixon@gmail.com
@@ -43,7 +48,7 @@ files:
43
48
  - .gitignore
44
49
  - Gemfile
45
50
  - LICENSE.txt
46
- - README.rdoc
51
+ - README.md
47
52
  - Rakefile
48
53
  - example.conf
49
54
  - example.json
@@ -53,27 +58,26 @@ files:
53
58
  - test/plugin/test_out_datacalculator.rb
54
59
  homepage: https://github.com/muddydixon/fluent-plugin-datacalculator
55
60
  licenses: []
61
+ metadata: {}
56
62
  post_install_message:
57
63
  rdoc_options: []
58
64
  require_paths:
59
65
  - lib
60
66
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
67
  requirements:
63
- - - ! '>='
68
+ - - '>='
64
69
  - !ruby/object:Gem::Version
65
70
  version: '0'
66
71
  required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
72
  requirements:
69
- - - ! '>='
73
+ - - '>='
70
74
  - !ruby/object:Gem::Version
71
75
  version: '0'
72
76
  requirements: []
73
77
  rubyforge_project: fluent-plugin-datacalculator
74
- rubygems_version: 1.8.11
78
+ rubygems_version: 2.0.14
75
79
  signing_key:
76
- specification_version: 3
80
+ specification_version: 4
77
81
  summary: Output filter plugin to calculate messages that matches specified conditions
78
82
  test_files:
79
83
  - test/helper.rb
@@ -1,52 +0,0 @@
1
- = fluent-plugin-datacalculator
2
-
3
- == Component
4
-
5
- === DataCalculateOutput
6
-
7
- Simple Calculate messages and summarize the calculated results.
8
-
9
- - Summarize calculated results per min/hour/day
10
- - Summarize calculated results per second (average every min/hour/day)
11
- - Use finalizer of summarized results (e.g. average)
12
-
13
- 'input_tag_remove_prefix' option available if you want to remove tag prefix from output field names.
14
-
15
- == Configuration
16
-
17
- === DataCalculateOutput
18
-
19
- <match accesslog.**>
20
- type datacalculate
21
- unit minute
22
- aggregate all
23
- fomulas sum = amount * price, amounts = amount
24
- </match>
25
-
26
- If you use finalizer, like this
27
-
28
- <match accesslog.**>
29
- type datacalculate
30
- unit minute
31
- aggregate all
32
- fomulas sum = amount * price, amounts = amount
33
- finalizer average = amounts > 0 ? 1.0 * sum / amounts : 0
34
- </match>
35
-
36
- Finalizer uses the summarized output, so argv in finalizer must exist in left-hand side in fomulas.
37
-
38
-
39
-
40
- == TODO
41
-
42
- - multiple finalizer
43
- - patches welcome!
44
-
45
- == Thanks
46
-
47
- tagomoris's fluent-plugin-datacounter is AWESOME plugin! That's nice!
48
-
49
- == Copyright
50
-
51
- Copyright:: Copyright (c) 2012- Muddy Dixon
52
- License:: Apache License, Version 2.0