fluent-plugin-numeric-monitor 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.
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-numeric-monitor"
4
- gem.version = "0.1.2"
4
+ gem.version = "0.1.3"
5
5
  gem.authors = ["TAGOMORI Satoshi"]
6
6
  gem.email = ["tagomoris@gmail.com"]
7
7
  gem.description = %q{Fluentd plugin to calculate min/max/avg/Xpercentile values, and emit these data as message}
@@ -113,12 +113,15 @@ class Fluent::NumericMonitorOutput < Fluent::Output
113
113
  if c[:num] then output['num'] = c[:num] end
114
114
  if c[:min] then output['min'] = c[:min] end
115
115
  if c[:max] then output['max'] = c[:max] end
116
- if c[:num] > 0 then output['avg'] = (c[:sum] * 100.0 / (c[:num] * 1.0)).round / 100 end
116
+ if c[:num] > 0 then output['avg'] = (c[:sum] * 100.0 / (c[:num] * 1.0)).round / 100.0 end
117
117
  if @percentiles
118
118
  sorted = c[:sample].sort
119
119
  @percentiles.each do |p|
120
120
  i = (c[:num] * p / 100).floor
121
- output["percentile_#{p}"] = c[:sample][i]
121
+ if i > 0
122
+ i -= 1
123
+ end
124
+ output["percentile_#{p}"] = sorted[i]
122
125
  end
123
126
  end
124
127
  return output
@@ -65,6 +65,39 @@ class NumericMonitorOutputTest < Test::Unit::TestCase
65
65
  assert_equal 100, r1['tag1_num']
66
66
  end
67
67
 
68
+ def test_emit_aggregate_all
69
+ d1 = create_driver(%[
70
+ unit minute
71
+ tag monitor.test
72
+ input_tag_remove_prefix test
73
+ aggregate all
74
+ monitor_key field1
75
+ percentiles 80,90
76
+ ], 'test.tag1')
77
+
78
+ d1.run do
79
+ 10.times do
80
+ d1.emit({'field1' => 0})
81
+ d1.emit({'field1' => '1'})
82
+ d1.emit({'field1' => 2})
83
+ d1.emit({'field1' => '3'})
84
+ d1.emit({'field1' => 4})
85
+ d1.emit({'field1' => 5})
86
+ d1.emit({'field1' => 6})
87
+ d1.emit({'field1' => 7})
88
+ d1.emit({'field1' => 8})
89
+ d1.emit({'field1' => 9})
90
+ end
91
+ end
92
+ r1 = d1.instance.flush
93
+ assert_equal 0, r1['min']
94
+ assert_equal 9, r1['max']
95
+ assert_equal 4.5, r1['avg']
96
+ assert_equal 7, r1['percentile_80']
97
+ assert_equal 8, r1['percentile_90']
98
+ assert_equal 100, r1['num']
99
+ end
100
+
68
101
  def test_without_percentiles
69
102
  d = create_driver(%[
70
103
  unit minute
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-numeric-monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-17 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd