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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 036f3acd030741392ec82058f22e3921cfb4bf3a
4
- data.tar.gz: 67a195961977e80ff7ef70e0d1418236a5ec7a4b
3
+ metadata.gz: c448a36c0de1af2d025a96065a51ebbaa29f3a67
4
+ data.tar.gz: a5e1b567b9c1d1ba0c2af2bebf3192aa1d001a4e
5
5
  SHA512:
6
- metadata.gz: a208ce10bcf0245ef0d5a36dde4134012583455881bcc370a16061cbed12b1cc7555df81725fc124cdd3c4bd9a8046440d39c7f2d4c15799d9c74609bf1872c5
7
- data.tar.gz: a2639f78d865f3e71a87d7ccb68aed91e1eb652c9cc6bc70d1bac0c04753d877e749a818791d98cf84801b1ba0036da508b5020c7be0182c96599c6693d0dfd4
6
+ metadata.gz: d8489b420002f513bca5414625211565e657ee66d0587c2e8280cc5e1b57adf7142aeabd0c5950724b8c2925c1e99ec2f7c1facb38105032fe5dba360da2e91e
7
+ data.tar.gz: 294c70be814bde4a92eaf25d385259dbde3b66491bf15560a462b3195bcc7540e11fb43b716d458e1ae296c5bf7004dc180e6c873719120c958232439bb803a3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.2 (2014/01/24)
2
+
3
+ Fixes
4
+
5
+ - Fix the case when input record keys are symbols
6
+
1
7
  ## 0.3.1 (2014/01/02)
2
8
 
3
9
  Fixes
@@ -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.1"
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 true
179
- sleep 0.5
180
+ while (sleep 0.1)
180
181
  begin
181
182
  if Fluent::Engine.now - @last_checked >= @interval
182
- now = Fluent::Engine.now
183
- flush_emit(now - @last_checked)
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(step)
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
@@ -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
- {"4xx_count"=>"3","5xx_count"=>2,"reqtime_max"=>1,"reqtime_min"=>3,"reqtime_avg"=>4},
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(0)
78
+ driver.instance.flush_emit
79
79
  end
80
80
  let(:empty_emit) do
81
- driver.instance.flush_emit(0)
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(0)
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.1
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-02 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd