fluent-plugin-groupcounter 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86658cfcab0fe4d17fcbafd52f8baa4063905316
4
- data.tar.gz: bd59e1fe0c665c9c942519d1eb026e9f258113d3
3
+ metadata.gz: c8cc4bf62fb23f54f31a2538cdf2ec1218e2970e
4
+ data.tar.gz: 8fe568adf912877846f3c26c0bb1426c2c0dba34
5
5
  SHA512:
6
- metadata.gz: 92bab15c3c80a69a66c131de63a99d3cfcc3e4a61eea8618603413e02cd142cd93c897cd87571db89faa7270eb0e4318d1d4ac97237bc3dd824ecdd05bbddf16
7
- data.tar.gz: 99cd15d0539ec3a0d898bdf4f6c8937111e523dca1acade1151c0e200500c1868717bd8196d76276991d671da9ec3f24f7bf977dea378d251e763d2589ea8c1e
6
+ metadata.gz: 13d484566258d0a0ce4b260baaebdfabb2763dcb5df908c684be4a8577173b6dbd2ddd590bbbf16ac170a080bb4b8a7675eefea15c72eed2152cd8c374b204e8
7
+ data.tar.gz: 93178c805d0fe9a19a206cfd3098a64cc51685f4daa0fb767a2bec45b25dc77b3f0656f85d075f2157b7b41ec63e83d0f88b05e17d1a0cd5d8e437b854e5461f
data/.gitignore CHANGED
@@ -9,4 +9,5 @@ vendor
9
9
  doc/*
10
10
  tmp/*
11
11
  .yardoc
12
-
12
+ pck/*
13
+ .ruby-version
data/README.md CHANGED
@@ -7,7 +7,7 @@ Fluentd plugin to count like SELECT COUNT(\*) GROUP BY.
7
7
  Assume inputs are coming as followings:
8
8
 
9
9
  apache.access: {"code":"200", "method":"GET", "path":"/index.html", "reqtime":"1.001" }
10
- apache.access: {"code":"404", "method":"GET", "path":"/foo.html", "reqtime":"2.002" }
10
+ apache.access: {"code":"202", "method":"GET", "path":"/foo.html", "reqtime":"2.002" }
11
11
  apache.access: {"code":"200", "method":"GET", "path":"/index.html", "reqtime":"3.003" }
12
12
 
13
13
  Think of quering `SELECT COUNT(\*) GROUP BY code,method,path`. Configuration becomes as below:
@@ -22,7 +22,7 @@ Think of quering `SELECT COUNT(\*) GROUP BY code,method,path`. Configuration bec
22
22
 
23
23
  Output becomes like
24
24
 
25
- groupcounter.apache.access: {"200_GET_/index.html_count":2, "404_GET_/foo.html_count":1}
25
+ groupcounter.apache.access: {"200_GET_/index.html_count":2, "202_GET_/foo.html_count":1}
26
26
 
27
27
  ## Parameters
28
28
 
@@ -34,6 +34,16 @@ Output becomes like
34
34
 
35
35
  Specify the delimiter to join `group_by_keys`. Default is '_'.
36
36
 
37
+ * pattern\[1-20\]
38
+
39
+ Use `patternX` option to apply grouping more roughly. For example, adding a configuration for the above example as below
40
+
41
+ pattern1 2xx ^2\d\d
42
+
43
+ gives you an ouput like
44
+
45
+ groupcounter.apache.access: {"2xx_GET_/index.html_count":3}
46
+
37
47
  * group\_by\_expression (semi-required)
38
48
 
39
49
  Use an expression to group the event record. `group_by_keys` or `group_by_expression` is required.
@@ -89,7 +99,7 @@ Output becomes like
89
99
 
90
100
  gives you an output like
91
101
 
92
- groupcounter.apache.access: {"200_GET_/index.html_reqtime_max":3.003, "404_GET_/foo.html_reqtime_max":2.002}
102
+ groupcounter.apache.access: {"200_GET_/index.html_reqtime_max":3.003, "202_GET_/foo.html_reqtime_max":2.002}
93
103
 
94
104
  * min\_key
95
105
 
@@ -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-groupcounter"
6
- s.version = "0.2.0"
6
+ s.version = "0.2.1"
7
7
  s.authors = ["Ryosuke IWANAGA", "Naotoshi SEO"]
8
8
  s.email = ["@riywo", "sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/riywo/fluent-plugin-groupcounter"
@@ -1,6 +1,8 @@
1
1
  class Fluent::GroupCounterOutput < Fluent::Output
2
2
  Fluent::Plugin.register_output('groupcounter', self)
3
3
 
4
+ PATTERN_MAX_NUM = 20
5
+
4
6
  def initialize
5
7
  super
6
8
  require 'pathname'
@@ -24,6 +26,7 @@ class Fluent::GroupCounterOutput < Fluent::Output
24
26
  config_param :min_suffix, :string, :default => '_min'
25
27
  config_param :avg_suffix, :string, :default => '_avg'
26
28
  config_param :store_file, :string, :default => nil
29
+ (1..PATTERN_MAX_NUM).each {|i| config_param "pattern#{i}".to_sym, :string, :default => nil }
27
30
 
28
31
  attr_accessor :count_interval
29
32
  attr_accessor :counts
@@ -69,6 +72,14 @@ class Fluent::GroupCounterOutput < Fluent::Output
69
72
 
70
73
  @group_by_keys = @group_by_keys.split(',') if @group_by_keys
71
74
 
75
+ @pattern = {}
76
+ (1..PATTERN_MAX_NUM).each do |i|
77
+ next unless conf["pattern#{i}"]
78
+ replace, regexp = conf["pattern#{i}"].split(/ +/, 2)
79
+ raise Fluent::ConfigError, "pattern#{i} does not contain 2 parameters" unless regexp
80
+ @pattern[replace] = Regexp.compile(regexp)
81
+ end
82
+
72
83
  if @store_file
73
84
  f = Pathname.new(@store_file)
74
85
  if (f.exist? && !f.writable_real?) || (!f.exist? && !f.parent.writable_real?)
@@ -231,6 +242,9 @@ class Fluent::GroupCounterOutput < Fluent::Output
231
242
  group_key = values.join(@delimiter)
232
243
  end
233
244
  group_key = group_key.to_s.force_encoding('ASCII-8BIT')
245
+
246
+ @pattern.each {|replace, regexp| break if group_key.gsub!(regexp, replace) }
247
+ group_key
234
248
  end
235
249
 
236
250
  def sum(a, b)
@@ -347,6 +347,38 @@ describe Fluent::GroupCounterOutput do
347
347
  it { emit }
348
348
  end
349
349
 
350
+ context 'pattern' do
351
+ # NOTE: \\d should be just \d in config file
352
+ let(:config) { CONFIG + %[
353
+ group_by_expression ${method}_${path.split("?")[0].split("/")[2]}/${code}
354
+ delimiter _
355
+ pattern1 201 201$
356
+ pattern2 2xx 2\\d\\d$
357
+ pattern3 4xx 4\\d\\d$
358
+ ]}
359
+ let(:messages) do
360
+ [
361
+ {"code" => "200", "method" => "GET", "path" => "/api/people/@me/@self?count=1", "reqtime" => 0.000 },
362
+ {"code" => "200", "method" => "POST", "path" => "/api/ngword?_method=check", "reqtime" => 1.001 },
363
+ {"code" => "400", "method" => "GET", "path" => "/api/messages/@me/@outbox", "reqtime" => 2.002 },
364
+ {"code" => "201", "method" => "GET", "path" => "/api/people/@me/@self", "reqtime" => 3.003 },
365
+ ]
366
+ end
367
+ let(:expected) do
368
+ {
369
+ "GET_people/201_count"=>1,
370
+ "GET_people/2xx_count"=>1,
371
+ "POST_ngword/2xx_count"=>1,
372
+ "GET_messages/4xx_count"=>1,
373
+ }
374
+ end
375
+ before do
376
+ Fluent::Engine.stub(:now).and_return(time)
377
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected)
378
+ end
379
+ it { emit }
380
+ end
381
+
350
382
  end
351
383
  end
352
384
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-groupcounter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryosuke IWANAGA