fluent-plugin-derive 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +4 -0
- data/fluent-plugin-derive.gemspec +1 -1
- data/lib/fluent/plugin/out_derive.rb +16 -2
- data/spec/out_derive_spec.rb +71 -0
- 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: 2edf79d1c0846b494a3e52d47d19078ed1b9ada0
|
4
|
+
data.tar.gz: 87e3e2840c5d56c7744a37bd4183de29db72ed93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aff057813ef913ebc37a08f2ce37a4654039a66c6f5a97219e3d041ce50742bf3ba3ef25b53b595e676e9bace83808aa38a8815c04146f274f1b89aff4fe1ebb
|
7
|
+
data.tar.gz: 74be1d87a51f67e61b8291bee976880f68c83c2af8dce03b07f9f765f56210f40609d647d658ef67d7555b82cb706d5cda94b8956a5f4789e04afe9f1a872981
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -99,6 +99,10 @@ Define the expected range value. If min and/or max are specified any value outsi
|
|
99
99
|
|
100
100
|
Optional. Divide the incleased value by interval time before output. The default is `true`. Set `false` for disable dividing.
|
101
101
|
|
102
|
+
* counter_mode
|
103
|
+
|
104
|
+
Optional. Use RRD's counter mode. The default is `false`. Set `true` for use RRD's counter.
|
105
|
+
|
102
106
|
## Contributing
|
103
107
|
|
104
108
|
1. Fork it
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-derive"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.4"
|
8
8
|
spec.authors = ["Nobuhiro Nikushi"]
|
9
9
|
spec.email = ["deneb.ge@gmail.com"]
|
10
10
|
spec.description = spec.summary
|
@@ -15,6 +15,7 @@ class Fluent::DeriveOutput < Fluent::Output
|
|
15
15
|
config_param :min, :integer, :default => nil
|
16
16
|
config_param :max, :integer, :default => nil
|
17
17
|
config_param :time_unit_division, :bool, :default => true
|
18
|
+
config_param :counter_mode, :bool, :default => false
|
18
19
|
|
19
20
|
# for test
|
20
21
|
attr_reader :key_pattern
|
@@ -157,9 +158,9 @@ class Fluent::DeriveOutput < Fluent::Output
|
|
157
158
|
return nil
|
158
159
|
end
|
159
160
|
if @time_unit_division
|
160
|
-
rate = (cur_value
|
161
|
+
rate = _calc_rate(cur_value , prev_value)/(cur_time - prev_time)
|
161
162
|
else
|
162
|
-
rate = cur_value
|
163
|
+
rate = _calc_rate(cur_value , prev_value)
|
163
164
|
end
|
164
165
|
if adjustment && adjustment[0] == '*'
|
165
166
|
rate * adjustment[1]
|
@@ -170,6 +171,19 @@ class Fluent::DeriveOutput < Fluent::Output
|
|
170
171
|
end
|
171
172
|
end
|
172
173
|
|
174
|
+
def _calc_rate(cur_value, prev_value)
|
175
|
+
rate = cur_value - prev_value
|
176
|
+
if @counter_mode
|
177
|
+
if rate < 0
|
178
|
+
rate += 2 ** 32 - 1
|
179
|
+
end
|
180
|
+
if rate < 0
|
181
|
+
rate += 2 ** 64 - 2 ** 32
|
182
|
+
end
|
183
|
+
end
|
184
|
+
rate
|
185
|
+
end
|
186
|
+
|
173
187
|
def truncate_min(value, min)
|
174
188
|
return nil unless value
|
175
189
|
(value < min) ? min : value
|
data/spec/out_derive_spec.rb
CHANGED
@@ -299,6 +299,77 @@ describe Fluent::DeriveOutput do
|
|
299
299
|
}
|
300
300
|
end
|
301
301
|
|
302
|
+
context 'counter_mode true 32bit' do
|
303
|
+
let(:config) { %[
|
304
|
+
counter_mode true
|
305
|
+
tag rate
|
306
|
+
key1 foo
|
307
|
+
time_unit_division false
|
308
|
+
]}
|
309
|
+
before do
|
310
|
+
driver.run {
|
311
|
+
driver.emit({'foo'=> 4294967295}, time)
|
312
|
+
driver.emit({'foo'=> 100}, time + 60)
|
313
|
+
}
|
314
|
+
end
|
315
|
+
it {
|
316
|
+
driver.emits[1].should == ['rate', time + 60, {'foo'=> 100}]
|
317
|
+
}
|
318
|
+
end
|
319
|
+
|
320
|
+
context 'counter_mode not set 32bit' do
|
321
|
+
let(:config) { %[
|
322
|
+
tag rate
|
323
|
+
key1 foo
|
324
|
+
time_unit_division false
|
325
|
+
]}
|
326
|
+
before do
|
327
|
+
driver.run {
|
328
|
+
driver.emit({'foo'=> 4294967295}, time)
|
329
|
+
driver.emit({'foo'=> 100}, time + 60)
|
330
|
+
}
|
331
|
+
end
|
332
|
+
it {
|
333
|
+
driver.emits[1].should == ['rate', time + 60, {'foo'=> -4294967195}]
|
334
|
+
}
|
335
|
+
end
|
336
|
+
|
337
|
+
context 'counter_mode true 64bit' do
|
338
|
+
let(:config) { %[
|
339
|
+
counter_mode true
|
340
|
+
tag rate
|
341
|
+
key1 foo
|
342
|
+
time_unit_division false
|
343
|
+
]}
|
344
|
+
before do
|
345
|
+
driver.run {
|
346
|
+
driver.emit({'foo'=> 18446744073709551615}, time)
|
347
|
+
driver.emit({'foo'=> 100}, time + 60)
|
348
|
+
}
|
349
|
+
end
|
350
|
+
it {
|
351
|
+
driver.emits[1].should == ['rate', time + 60, {'foo'=> 100}]
|
352
|
+
}
|
353
|
+
end
|
354
|
+
|
355
|
+
context 'counter_mode not set 64bit' do
|
356
|
+
let(:config) { %[
|
357
|
+
tag rate
|
358
|
+
key1 foo
|
359
|
+
time_unit_division false
|
360
|
+
]}
|
361
|
+
before do
|
362
|
+
driver.run {
|
363
|
+
driver.emit({'foo'=> 18446744073709551615}, time)
|
364
|
+
driver.emit({'foo'=> 100}, time + 60)
|
365
|
+
}
|
366
|
+
end
|
367
|
+
it {
|
368
|
+
driver.emits[1].should == ['rate', time + 60, {'foo'=> -18446744073709551515}]
|
369
|
+
}
|
370
|
+
end
|
371
|
+
|
372
|
+
|
302
373
|
end
|
303
374
|
end
|
304
375
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-derive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobuhiro Nikushi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.5.1
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: fluentd plugin to derive rate
|