fluent-plugin-datacounter 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -51,7 +51,8 @@ HTTP status code patterns.
51
51
 
52
52
  <match accesslog.**>
53
53
  type datacounter
54
- unit minute
54
+ count_interval 1m # just same as 'unit minute' and 'count_interval 60s'
55
+ # you can also specify '30s', '5m', '2h' ....
55
56
  count_key status
56
57
  # patternX: X(1-9)
57
58
  pattern1 2xx ^2\d\d$
@@ -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-datacounter"
6
- s.version = "0.1.1"
6
+ s.version = "0.2.0"
7
7
  s.authors = ["TAGOMORI Satoshi"]
8
8
  s.email = ["tagomoris@gmail.com"]
9
9
  s.homepage = "https://github.com/tagomoris/fluent-plugin-datacounter"
@@ -1,6 +1,7 @@
1
1
  class Fluent::DataCounterOutput < Fluent::Output
2
2
  Fluent::Plugin.register_output('datacounter', self)
3
3
 
4
+ config_param :count_interval, :time, :default => nil
4
5
  config_param :unit, :string, :default => 'minute'
5
6
  config_param :aggregate, :string, :default => 'tag'
6
7
  config_param :tag, :string, :default => 'datacount'
@@ -13,19 +14,25 @@ class Fluent::DataCounterOutput < Fluent::Output
13
14
  config_param ('pattern' + i.to_s).to_sym, :string, :default => nil # NAME REGEXP
14
15
  end
15
16
 
17
+ attr_accessor :tick
16
18
  attr_accessor :counts
17
19
  attr_accessor :last_checked
18
20
 
19
21
  def configure(conf)
20
22
  super
21
23
 
22
- @unit = case @unit
23
- when 'minute' then :minute
24
- when 'hour' then :hour
25
- when 'day' then :day
26
- else
27
- raise Fluent::ConfigError, "flowcounter unit allows minute/hour/day"
28
- end
24
+ if @count_interval
25
+ @tick = @count_interval.to_i
26
+ else
27
+ @tick = case @unit
28
+ when 'minute' then 60
29
+ when 'hour' then 3600
30
+ when 'day' then 86400
31
+ else
32
+ raise RuntimeError, "@unit must be one of minute/hour/day"
33
+ end
34
+ end
35
+
29
36
  @aggregate = case @aggregate
30
37
  when 'tag' then :tag
31
38
  when 'all' then :all
@@ -144,16 +151,9 @@ class Fluent::DataCounterOutput < Fluent::Output
144
151
  def watch
145
152
  # instance variable, and public accessable, for test
146
153
  @last_checked = Fluent::Engine.now
147
- tick = case @unit
148
- when :minute then 60
149
- when :hour then 3600
150
- when :day then 86400
151
- else
152
- raise RuntimeError, "@unit must be one of minute/hour/day"
153
- end
154
154
  while true
155
155
  sleep 0.5
156
- if Fluent::Engine.now - @last_checked >= tick
156
+ if Fluent::Engine.now - @last_checked >= @tick
157
157
  now = Fluent::Engine.now
158
158
  flush_emit(now - @last_checked)
159
159
  @last_checked = now
@@ -58,12 +58,45 @@ class DataCounterOutputTest < Test::Unit::TestCase
58
58
  count_key field
59
59
  pattern1 ok ^2\\d\\d$
60
60
  ]
61
- assert_equal :minute, d.instance.unit
61
+ assert_equal 60, d.instance.tick
62
62
  assert_equal :tag, d.instance.aggregate
63
63
  assert_equal 'datacount', d.instance.tag
64
64
  assert_nil d.instance.input_tag_remove_prefix
65
65
  assert_equal 'field', d.instance.count_key
66
66
  assert_equal 'ok ^2\d\d$', d.instance.pattern1
67
+
68
+ d1 = create_driver %[
69
+ unit minute
70
+ count_key field
71
+ pattern1 ok ^2\\d\\d$
72
+ ]
73
+ d2 = create_driver %[
74
+ count_interval 60s
75
+ count_key field
76
+ pattern1 ok ^2\\d\\d$
77
+ ]
78
+ assert_equal d1.instance.tick, d2.instance.tick
79
+
80
+ d = create_driver %[
81
+ count_interval 5m
82
+ count_key field
83
+ pattern1 ok ^2\\d\\d$
84
+ ]
85
+ assert_equal 300, d.instance.tick
86
+
87
+ d = create_driver %[
88
+ count_interval 2h
89
+ count_key field
90
+ pattern1 ok ^2\\d\\d$
91
+ ]
92
+ assert_equal 7200, d.instance.tick
93
+
94
+ d = create_driver %[
95
+ count_interval 30s
96
+ count_key field
97
+ pattern1 ok ^2\\d\\d$
98
+ ]
99
+ assert_equal 30, d.instance.tick
67
100
  end
68
101
 
69
102
  def test_count_initialized
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-datacounter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
16
- requirement: &2161613960 !ruby/object:Gem::Requirement
16
+ requirement: &2160689900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2161613960
24
+ version_requirements: *2160689900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fluentd
27
- requirement: &2161613520 !ruby/object:Gem::Requirement
27
+ requirement: &2160689460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2161613520
35
+ version_requirements: *2160689460
36
36
  description: Output filter plugin to count messages that matches specified conditions
37
37
  email:
38
38
  - tagomoris@gmail.com