fluent-plugin-grepcounter 0.1.2 → 0.1.3
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 +38 -2
- data/fluent-plugin-grepcounter.gemspec +1 -1
- data/lib/fluent/plugin/out_grepcounter.rb +11 -8
- data/spec/out_grepcounter_spec.rb +48 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cceea9a84d43542c30eda8ae0b2d3127d3a8ee8a
|
4
|
+
data.tar.gz: ed10007f880499d164493b9c42a5edaefb0525c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66b848914ad05a5f45ddc55cdd3e3e0c01dbd5046879cd1bef6a910f194e23cf6b3ce631a9b008b03d0ce5fc27747e64b049ed10d08ce7768334250c637014b3
|
7
|
+
data.tar.gz: f5f6c761d747e58dc7ed9f14e94383221e7476376bf1764e22ac777e14c42aa86d54f538fe77a35ce1e2ad01748ce70164543e44a1faf0e42677b7c441c55b80
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -45,7 +45,7 @@ Another example of grepcounter configuration to use `output_with_joined_delimite
|
|
45
45
|
output_with_joined_delimiter \n
|
46
46
|
</source>
|
47
47
|
|
48
|
-
Then, output bocomes as belows (indented). You can
|
48
|
+
Then, output bocomes as belows (indented). You can see the `message` field is joined with \n.
|
49
49
|
|
50
50
|
warn.count.syslog.host1: {
|
51
51
|
"count":2,
|
@@ -56,14 +56,50 @@ Then, output bocomes as belows (indented). You can use the `message` field is jo
|
|
56
56
|
|
57
57
|
## Parameters
|
58
58
|
|
59
|
+
- count\_interval
|
60
|
+
|
61
|
+
The interval time to count in seconds. Default is 60.
|
62
|
+
|
63
|
+
- input\_key
|
64
|
+
|
65
|
+
The target field key to grep out
|
66
|
+
|
67
|
+
- regexp
|
68
|
+
|
69
|
+
The filtering regular expression
|
70
|
+
|
71
|
+
- exclude
|
72
|
+
|
73
|
+
The excluding regular expression like grep -v
|
74
|
+
|
75
|
+
- threshold
|
76
|
+
|
77
|
+
The threshold number to emit
|
78
|
+
|
79
|
+
- comparison
|
80
|
+
|
81
|
+
The comparison operator for the threshold (either of `>=` or `<=`). Default is `>=`, i.e., emit if count >= threshold.
|
82
|
+
|
83
|
+
- output\_with\_joined\_delimiter
|
84
|
+
|
85
|
+
Join the output message array field with the specified delimiter to make the output message be a string.
|
86
|
+
|
59
87
|
- aggregate
|
60
88
|
|
61
89
|
Count by each `tag` or `all`. The default value is `tag`.
|
62
90
|
|
63
|
-
-
|
91
|
+
- output\_tag
|
64
92
|
|
65
93
|
The output tag. Required for aggregate `all`.
|
66
94
|
|
95
|
+
- add\_tag\_prefix
|
96
|
+
|
97
|
+
Add tag prefix for output message
|
98
|
+
|
99
|
+
- replace\_invalid\_sequence
|
100
|
+
|
101
|
+
Replace invalid byte sequence in UTF-8 with '?' character if `true`
|
102
|
+
|
67
103
|
## ChaangeLog
|
68
104
|
|
69
105
|
See [CHANGELOG.md](CHANGELOG.md) for details.
|
@@ -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-grepcounter"
|
6
|
-
s.version = "0.1.
|
6
|
+
s.version = "0.1.3"
|
7
7
|
s.authors = ["Naotoshi SEO"]
|
8
8
|
s.email = ["sonots@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-grepcounter"
|
@@ -7,6 +7,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
7
7
|
config_param :count_interval, :time, :default => 5
|
8
8
|
config_param :exclude, :string, :default => nil
|
9
9
|
config_param :threshold, :integer, :default => 1
|
10
|
+
config_param :comparison, :string, :default => '>='
|
10
11
|
config_param :output_tag, :string, :default => nil
|
11
12
|
config_param :add_tag_prefix, :string, :default => 'count'
|
12
13
|
config_param :output_with_joined_delimiter, :string, :default => nil
|
@@ -25,15 +26,19 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
25
26
|
@exclude = Regexp.compile(@exclude) if @exclude
|
26
27
|
@threshold = @threshold.to_i
|
27
28
|
|
29
|
+
unless ['>=', '<='].include?(@comparison)
|
30
|
+
raise Fluent::ConfigError, "grepcounter: comparison allows >=, <="
|
31
|
+
end
|
32
|
+
|
28
33
|
unless ['tag', 'all'].include?(@aggregate)
|
29
|
-
raise Fluent::ConfigError, "grepcounter aggregate allows tag/all"
|
34
|
+
raise Fluent::ConfigError, "grepcounter: aggregate allows tag/all"
|
30
35
|
end
|
31
36
|
|
32
37
|
case @aggregate
|
33
38
|
when 'all'
|
34
|
-
raise Fluent::ConfigError, "output_tag must be specified with aggregate all" if @output_tag.nil?
|
39
|
+
raise Fluent::ConfigError, "grepcounter: output_tag must be specified with aggregate all" if @output_tag.nil?
|
35
40
|
when 'tag'
|
36
|
-
# raise Fluent::ConfigError, "add_tag_prefix must be specified with aggregate tag" if @add_tag_prefix.nil?
|
41
|
+
# raise Fluent::ConfigError, "grepcounter: add_tag_prefix must be specified with aggregate tag" if @add_tag_prefix.nil?
|
37
42
|
end
|
38
43
|
|
39
44
|
@matches = {}
|
@@ -72,8 +77,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
72
77
|
|
73
78
|
chain.next
|
74
79
|
rescue => e
|
75
|
-
$log.warn e.message
|
76
|
-
$log.warn e.backtrace.join(', ')
|
80
|
+
$log.warn "grepcounter: #{e.class} #{e.message} #{e.backtrace.first}"
|
77
81
|
end
|
78
82
|
|
79
83
|
# thread callback
|
@@ -89,8 +93,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
89
93
|
@last_checked = now
|
90
94
|
end
|
91
95
|
rescue => e
|
92
|
-
$log.warn e.message
|
93
|
-
$log.warn e.backtrace.join(", ")
|
96
|
+
$log.warn "grepcounter: #{e.class} #{e.message} #{e.backtrace.first}"
|
94
97
|
end
|
95
98
|
end
|
96
99
|
end
|
@@ -121,7 +124,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
121
124
|
|
122
125
|
def generate_output(count, matches, tag = nil)
|
123
126
|
return nil if count.nil?
|
124
|
-
return nil
|
127
|
+
return nil unless eval("#{count} #{@comparison} #{@threshold}")
|
125
128
|
output = {}
|
126
129
|
output['count'] = count
|
127
130
|
output['message'] = @output_with_joined_delimiter.nil? ? matches : matches.join(@output_with_joined_delimiter)
|
@@ -40,6 +40,15 @@ describe Fluent::GrepCounterOutput do
|
|
40
40
|
end
|
41
41
|
it { expect { driver }.to raise_error(Fluent::ConfigError) }
|
42
42
|
end
|
43
|
+
|
44
|
+
context 'invalid comparison' do
|
45
|
+
let(:config) do
|
46
|
+
CONFIG + %[
|
47
|
+
comparison foo
|
48
|
+
]
|
49
|
+
end
|
50
|
+
it { expect { driver }.to raise_error(Fluent::ConfigError) }
|
51
|
+
end
|
43
52
|
end
|
44
53
|
|
45
54
|
describe 'good configuration' do
|
@@ -52,6 +61,7 @@ describe Fluent::GrepCounterOutput do
|
|
52
61
|
its(:regexp) { should be_nil }
|
53
62
|
its(:exclude) { should be_nil }
|
54
63
|
its(:threshold) { should == 1 }
|
64
|
+
its(:comparison) { should == '>=' }
|
55
65
|
its(:output_tag) { should be_nil }
|
56
66
|
its(:add_tag_prefix) { should == 'count' }
|
57
67
|
end
|
@@ -121,7 +131,7 @@ describe Fluent::GrepCounterOutput do
|
|
121
131
|
it { emit }
|
122
132
|
end
|
123
133
|
|
124
|
-
context 'threshold (
|
134
|
+
context 'threshold (hit)' do
|
125
135
|
let(:config) do
|
126
136
|
CONFIG + %[
|
127
137
|
regexp WARN
|
@@ -139,7 +149,7 @@ describe Fluent::GrepCounterOutput do
|
|
139
149
|
it { emit }
|
140
150
|
end
|
141
151
|
|
142
|
-
context 'threshold (
|
152
|
+
context 'threshold (miss)' do
|
143
153
|
let(:config) do
|
144
154
|
CONFIG + %[
|
145
155
|
regexp WARN
|
@@ -248,6 +258,42 @@ describe Fluent::GrepCounterOutput do
|
|
248
258
|
end
|
249
259
|
it { expect { emit }.not_to raise_error(ArgumentError) }
|
250
260
|
end
|
261
|
+
|
262
|
+
describe "comparison <=" do
|
263
|
+
context 'threshold (hit)' do
|
264
|
+
let(:config) do
|
265
|
+
CONFIG + %[
|
266
|
+
regexp WARN
|
267
|
+
threshold 3
|
268
|
+
comparison <=
|
269
|
+
]
|
270
|
+
end
|
271
|
+
before do
|
272
|
+
Fluent::Engine.stub(:now).and_return(time)
|
273
|
+
Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, {"count"=>3,
|
274
|
+
"message"=>["2013/01/13T07:02:13.232645 WARN POST /auth","2013/01/13T07:02:21.542145 WARN GET /favicon.ico","2013/01/13T07:02:43.632145 WARN POST /login"],
|
275
|
+
"input_tag" => tag,
|
276
|
+
"input_tag_last" => tag.split('.').last,
|
277
|
+
})
|
278
|
+
end
|
279
|
+
it { emit }
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'threshold (miss)' do
|
283
|
+
let(:config) do
|
284
|
+
CONFIG + %[
|
285
|
+
regexp WARN
|
286
|
+
threshold 2
|
287
|
+
comparison <=
|
288
|
+
]
|
289
|
+
end
|
290
|
+
before do
|
291
|
+
Fluent::Engine.stub(:now).and_return(time)
|
292
|
+
Fluent::Engine.should_not_receive(:emit)
|
293
|
+
end
|
294
|
+
it { emit }
|
295
|
+
end
|
296
|
+
end
|
251
297
|
end
|
252
298
|
end
|
253
299
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-grepcounter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
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-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project: fluent-plugin-grepcounter
|
123
|
-
rubygems_version: 2.0.
|
123
|
+
rubygems_version: 2.0.2
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Count the number of matched messages
|