fluent-plugin-stats 0.3.1 → 0.3.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/fluent-plugin-stats.gemspec +1 -1
- data/lib/fluent/plugin/out_stats.rb +17 -6
- data/spec/out_stats_spec.rb +4 -4
- 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: c448a36c0de1af2d025a96065a51ebbaa29f3a67
|
|
4
|
+
data.tar.gz: a5e1b567b9c1d1ba0c2af2bebf3192aa1d001a4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8489b420002f513bca5414625211565e657ee66d0587c2e8280cc5e1b57adf7142aeabd0c5950724b8c2925c1e99ec2f7c1facb38105032fe5dba360da2e91e
|
|
7
|
+
data.tar.gz: 294c70be814bde4a92eaf25d385259dbde3b66491bf15560a462b3195bcc7540e11fb43b716d458e1ae296c5bf7004dc180e6c873719120c958232439bb803a3
|
data/CHANGELOG.md
CHANGED
data/fluent-plugin-stats.gemspec
CHANGED
|
@@ -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-stats"
|
|
6
|
-
s.version = "0.3.
|
|
6
|
+
s.version = "0.3.2"
|
|
7
7
|
s.authors = ["Naotoshi Seo"]
|
|
8
8
|
s.email = ["sonots@gmail.com"]
|
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-stats"
|
|
@@ -114,6 +114,7 @@ class Fluent::StatsOutput < Fluent::Output
|
|
|
114
114
|
# stats
|
|
115
115
|
matches = { :count => 0, :sum => {}, :max => {}, :min => {}, :avg => {} }
|
|
116
116
|
es.each do |time, record|
|
|
117
|
+
record = stringify_keys(record)
|
|
117
118
|
@sum_keys.each do |key|
|
|
118
119
|
next unless record[key] and value = record[key].to_f
|
|
119
120
|
matches[:sum][key] = sum(matches[:sum][key], value)
|
|
@@ -131,6 +132,7 @@ class Fluent::StatsOutput < Fluent::Output
|
|
|
131
132
|
matches[:avg][key] = sum(matches[:avg][key], value)
|
|
132
133
|
end
|
|
133
134
|
record.keys.each do |key|
|
|
135
|
+
key = key.to_s
|
|
134
136
|
value = record[key].to_f
|
|
135
137
|
if @sum and @sum.match(key)
|
|
136
138
|
matches[:sum][key] = sum(matches[:sum][key], value)
|
|
@@ -175,13 +177,11 @@ class Fluent::StatsOutput < Fluent::Output
|
|
|
175
177
|
def watcher
|
|
176
178
|
# instance variable, and public accessable, for test
|
|
177
179
|
@last_checked ||= Fluent::Engine.now
|
|
178
|
-
while
|
|
179
|
-
sleep 0.5
|
|
180
|
+
while (sleep 0.1)
|
|
180
181
|
begin
|
|
181
182
|
if Fluent::Engine.now - @last_checked >= @interval
|
|
182
|
-
|
|
183
|
-
flush_emit
|
|
184
|
-
@last_checked = now
|
|
183
|
+
@last_checked = Fluent::Engine.now
|
|
184
|
+
flush_emit
|
|
185
185
|
end
|
|
186
186
|
rescue => e
|
|
187
187
|
$log.warn "#{e.class} #{e.message} #{e.backtrace.first}"
|
|
@@ -190,7 +190,7 @@ class Fluent::StatsOutput < Fluent::Output
|
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
# This method is the real one to emit
|
|
193
|
-
def flush_emit
|
|
193
|
+
def flush_emit
|
|
194
194
|
time = Fluent::Engine.now
|
|
195
195
|
flushed_matches, @matches = @matches, initial_matches(@matches)
|
|
196
196
|
|
|
@@ -304,6 +304,17 @@ class Fluent::StatsOutput < Fluent::Output
|
|
|
304
304
|
end
|
|
305
305
|
|
|
306
306
|
private
|
|
307
|
+
def transform_keys(hash)
|
|
308
|
+
result = {}
|
|
309
|
+
hash.each_key do |key|
|
|
310
|
+
result[yield(key)] = hash[key]
|
|
311
|
+
end
|
|
312
|
+
result
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def stringify_keys(hash)
|
|
316
|
+
transform_keys(hash) { |key| key.to_s }
|
|
317
|
+
end
|
|
307
318
|
|
|
308
319
|
def lstrip(string, substring)
|
|
309
320
|
string.index(substring) == 0 ? string[substring.size..-1] : string
|
data/spec/out_stats_spec.rb
CHANGED
|
@@ -70,15 +70,15 @@ describe Fluent::StatsOutput do
|
|
|
70
70
|
[
|
|
71
71
|
{"4xx_count"=>"1","5xx_count"=>2,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3},
|
|
72
72
|
{"4xx_count"=>"2","5xx_count"=>2,"reqtime_max"=>5,"reqtime_min"=>2,"reqtime_avg"=>2},
|
|
73
|
-
{
|
|
73
|
+
{:'4xx_count'=>"3",:'5xx_count'=>2,:reqtime_max=>1,:reqtime_min=>3,:reqtime_avg=>4},
|
|
74
74
|
]
|
|
75
75
|
end
|
|
76
76
|
let(:emit) do
|
|
77
77
|
driver.run { messages.each {|message| driver.emit(message, time) } }
|
|
78
|
-
driver.instance.flush_emit
|
|
78
|
+
driver.instance.flush_emit
|
|
79
79
|
end
|
|
80
80
|
let(:empty_emit) do
|
|
81
|
-
driver.instance.flush_emit
|
|
81
|
+
driver.instance.flush_emit
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
context 'sum/max/min/avg' do
|
|
@@ -219,7 +219,7 @@ describe Fluent::StatsOutput do
|
|
|
219
219
|
let(:emit) do
|
|
220
220
|
driver.run { messages.each {|message| driver.emit_with_tag(message, time, 'foo.bar') } }
|
|
221
221
|
driver.run { messages.each {|message| driver.emit_with_tag(message, time, 'foo.bar2') } }
|
|
222
|
-
driver.instance.flush_emit
|
|
222
|
+
driver.instance.flush_emit
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
context 'aggregate all' do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-stats
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.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: 2014-01-
|
|
11
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fluentd
|