fluent-plugin-grepcounter 0.1.1 → 0.1.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/fluent-plugin-grepcounter.gemspec +1 -1
- data/lib/fluent/plugin/out_grepcounter.rb +36 -6
- data/spec/out_grepcounter_spec.rb +33 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55fb88fa0e4693f083e614072f4e4b39a977e4dc
|
4
|
+
data.tar.gz: 6a34586f73d49333d97fddd3ce51c33c2033c40b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01453ec71582eaed4d7a0d505dbcbfd93e3708debf9766ecb6c820679d5e85c4a1db0d8290981db628abc1fd6fc0d3ace701d097ee72ad57f722c178f1f1d65e
|
7
|
+
data.tar.gz: d3634e8a26b8dd3dbb04031248bc695c920d1987b7e2b62491cf36a5acd039d2ac683a19169025c7e795a360ca78d93890ffcccd15b9ccb7574cf7eda1ca15d7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ Then, output bocomes as belows (indented):
|
|
32
32
|
"input_tag_last":"host1",
|
33
33
|
}
|
34
34
|
|
35
|
-
Another example of grepcounter configuration to use `
|
35
|
+
Another example of grepcounter configuration to use `output_with_joined_delimiter`:
|
36
36
|
|
37
37
|
<match syslog.**>
|
38
38
|
type grepcounter
|
@@ -42,7 +42,7 @@ Another example of grepcounter configuration to use `output_delimiter`:
|
|
42
42
|
exclude favicon.ico
|
43
43
|
threshold 1
|
44
44
|
add_tag_prefix warn.count
|
45
|
-
|
45
|
+
output_with_joined_delimiter \n
|
46
46
|
</source>
|
47
47
|
|
48
48
|
Then, output bocomes as belows (indented). You can use the `message` field is joined with \n.
|
@@ -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.2"
|
7
7
|
s.authors = ["Naotoshi SEO"]
|
8
8
|
s.email = ["sonots@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-grepcounter"
|
@@ -11,6 +11,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
11
11
|
config_param :add_tag_prefix, :string, :default => 'count'
|
12
12
|
config_param :output_with_joined_delimiter, :string, :default => nil
|
13
13
|
config_param :aggregate, :string, :default => 'tag'
|
14
|
+
config_param :replace_invalid_sequence, :bool, :default => false
|
14
15
|
|
15
16
|
attr_accessor :matches
|
16
17
|
attr_accessor :last_checked
|
@@ -57,8 +58,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
57
58
|
# filter out and insert
|
58
59
|
es.each do |time,record|
|
59
60
|
value = record[@input_key]
|
60
|
-
next
|
61
|
-
next if @exclude and @exclude.match(value)
|
61
|
+
next unless match(value.to_s)
|
62
62
|
matches << value
|
63
63
|
count += 1
|
64
64
|
end
|
@@ -71,6 +71,9 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
71
71
|
end
|
72
72
|
|
73
73
|
chain.next
|
74
|
+
rescue => e
|
75
|
+
$log.warn e.message
|
76
|
+
$log.warn e.backtrace.join(', ')
|
74
77
|
end
|
75
78
|
|
76
79
|
# thread callback
|
@@ -79,10 +82,15 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
79
82
|
@last_checked = Fluent::Engine.now
|
80
83
|
while true
|
81
84
|
sleep 0.5
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
85
|
+
begin
|
86
|
+
if Fluent::Engine.now - @last_checked >= @count_interval
|
87
|
+
now = Fluent::Engine.now
|
88
|
+
flush_emit(now - @last_checked)
|
89
|
+
@last_checked = now
|
90
|
+
end
|
91
|
+
rescue => e
|
92
|
+
$log.warn e.message
|
93
|
+
$log.warn e.backtrace.join(", ")
|
86
94
|
end
|
87
95
|
end
|
88
96
|
end
|
@@ -112,6 +120,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
112
120
|
end
|
113
121
|
|
114
122
|
def generate_output(count, matches, tag = nil)
|
123
|
+
return nil if count.nil?
|
115
124
|
return nil if count < @threshold
|
116
125
|
output = {}
|
117
126
|
output['count'] = count
|
@@ -123,4 +132,25 @@ class Fluent::GrepCounterOutput < Fluent::Output
|
|
123
132
|
output
|
124
133
|
end
|
125
134
|
|
135
|
+
def match(string)
|
136
|
+
begin
|
137
|
+
return false if @regexp and !@regexp.match(string)
|
138
|
+
return false if @exclude and @exclude.match(string)
|
139
|
+
rescue ArgumentError => e
|
140
|
+
unless e.message.index("invalid byte sequence in") == 0
|
141
|
+
raise
|
142
|
+
end
|
143
|
+
string = replace_invalid_byte(string)
|
144
|
+
return false if @regexp and !@regexp.match(string)
|
145
|
+
return false if @exclude and @exclude.match(string)
|
146
|
+
end
|
147
|
+
return true
|
148
|
+
end
|
149
|
+
|
150
|
+
def replace_invalid_byte(string)
|
151
|
+
replace_options = { invalid: :replace, undef: :replace, replace: '?' }
|
152
|
+
original_encoding = string.encoding
|
153
|
+
temporal_encoding = (original_encoding == Encoding::UTF_8 ? Encoding::UTF_16BE : Encoding::UTF_8)
|
154
|
+
string.encode(temporal_encoding, original_encoding, replace_options).encode(original_encoding)
|
155
|
+
end
|
126
156
|
end
|
@@ -1,6 +1,13 @@
|
|
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::GrepCounterOutput do
|
5
12
|
before { Fluent::Test.setup }
|
6
13
|
CONFIG = %[
|
@@ -202,6 +209,12 @@ describe Fluent::GrepCounterOutput do
|
|
202
209
|
end
|
203
210
|
|
204
211
|
context 'aggregate all' do
|
212
|
+
let(:emit) do
|
213
|
+
driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar') } }
|
214
|
+
driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar2') } }
|
215
|
+
driver.instance.flush_emit(0)
|
216
|
+
end
|
217
|
+
|
205
218
|
let(:config) do
|
206
219
|
CONFIG + %[
|
207
220
|
regexp WARN
|
@@ -211,12 +224,30 @@ describe Fluent::GrepCounterOutput do
|
|
211
224
|
end
|
212
225
|
before do
|
213
226
|
Fluent::Engine.stub(:now).and_return(time)
|
214
|
-
Fluent::Engine.should_receive(:emit).with("count", time, {"count"=>3,
|
215
|
-
"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"],
|
227
|
+
Fluent::Engine.should_receive(:emit).with("count", time, {"count"=>3*2,
|
228
|
+
"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"]*2,
|
216
229
|
})
|
217
230
|
end
|
218
231
|
it { emit }
|
219
232
|
end
|
233
|
+
|
234
|
+
context 'replace_invalid_sequence' do
|
235
|
+
let(:config) do
|
236
|
+
CONFIG + %[
|
237
|
+
regexp WARN
|
238
|
+
replace_invalid_sequence true
|
239
|
+
]
|
240
|
+
end
|
241
|
+
let(:messages) do
|
242
|
+
[
|
243
|
+
"\xff".force_encoding('UTF-8'),
|
244
|
+
]
|
245
|
+
end
|
246
|
+
before do
|
247
|
+
Fluent::Engine.stub(:now).and_return(time)
|
248
|
+
end
|
249
|
+
it { expect { emit }.not_to raise_error(ArgumentError) }
|
250
|
+
end
|
220
251
|
end
|
221
252
|
end
|
222
253
|
|
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.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-
|
11
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|