observed-gauge 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +5 -0
- data/lib/observed/gauge.rb +11 -13
- data/lib/observed/gauge/version.rb +1 -1
- data/observed-gauge.gemspec +1 -1
- data/spec/gauge_spec.rb +7 -7
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZWYyNDJmNjFmOGFiY2NiZWM2YmE4NWM1YWM2Mjg4Yzg2MjFjZTlhNmQzN2My
|
10
|
-
MDIwYzIwYmYzZDI3N2U5NjNiYzczNGM5ZjkzNjg0NDdjYWM2NTAzNmEwODMx
|
11
|
-
OWVhZWNkNTI1NGY0MDYxNWMxYWU3ZGUyMzRjODBkNmNkNGQzZjg=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MGM5MzYxYjg5NDYzYWEyOGVjNzExYjA1OGE2N2RjNmNhNzcyYmE2YWMwMDEx
|
14
|
-
MDNjNGM2NDhjNDU4OGY4MDM2YzBkYjg2OWRhY2E3ZTA2M2FmODQxNGMzMDY3
|
15
|
-
NDVkNzUzNjI5YTczNGY0OTZkZGRmOThjN2RkY2VkZWY1ZWQ2ODE=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d6e48aeff83af1c9c8db48ca47ad0bd004a66f1
|
4
|
+
data.tar.gz: 1fd5740b7b989613086e7bceef0193dc02f810fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70f6c417546a34c6241d6ee0e0172e655024b8b9b35bd5b9bbc00300ab1e2773fa7fce7fae1afc5fa916325f100c1409db44951694908c224dc6ba0df104e923
|
7
|
+
data.tar.gz: 8f0a517c62804f6c6e360a3f6c76cf40173e195d4771679643d924ad3d3d3bf962bb03a8b002403bd1908a3a1b892267f2c8863ce9556807b2cd32749c8040d0
|
data/README.md
CHANGED
data/lib/observed/gauge.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'observed/
|
1
|
+
require 'observed/logging'
|
2
|
+
require 'observed/translator'
|
2
3
|
require 'observed/reporter/regexp_matching'
|
3
4
|
require 'observed/gauge/version'
|
4
5
|
require 'logger'
|
@@ -6,39 +7,40 @@ require 'rrd'
|
|
6
7
|
|
7
8
|
module Observed
|
8
9
|
module Plugins
|
9
|
-
class Gauge < Observed::
|
10
|
+
class Gauge < Observed::Translator
|
10
11
|
|
11
12
|
plugin_name 'gauge'
|
12
13
|
|
14
|
+
include Observed::Logging
|
13
15
|
include Observed::Reporter::RegexpMatching
|
14
16
|
|
15
|
-
attribute :tag
|
16
17
|
attribute :key_path
|
17
18
|
attribute :coerce, default: ->(data){ data }
|
18
19
|
attribute :rrd
|
19
20
|
attribute :step
|
20
21
|
attribute :period
|
21
22
|
|
22
|
-
def
|
23
|
+
def translate(data, options)
|
24
|
+
time = options[:time] || Time.now
|
23
25
|
rewrote = update_value_for_key_path(data, key_path) do |v|
|
24
26
|
sample = coerce.call(v)
|
25
27
|
average = get_cdp_updated_with(time, sample)
|
26
28
|
average
|
27
29
|
end
|
28
30
|
unless fetch_value_for_key_path(rewrote, key_path).nan?
|
29
|
-
|
31
|
+
rewrote
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
35
|
def prepare_rrd(args)
|
34
36
|
start = args[:start]
|
35
|
-
|
37
|
+
log_debug "Creating a rrd file named '#{args[:rrd]}' with options {:start => #{start}}"
|
36
38
|
result = RRD::Builder.new(args[:rrd], start: start, step: step.seconds).tap do |builder|
|
37
39
|
builder.datasource data_source, :type => :gauge, :heartbeat => period.seconds, :min => 0, :max => :unlimited
|
38
40
|
builder.archive :average, :every => period.seconds, :during => period.seconds
|
39
41
|
builder.save
|
40
42
|
end
|
41
|
-
|
43
|
+
log_debug "Builder#save returned: #{result.inspect}"
|
42
44
|
end
|
43
45
|
|
44
46
|
private
|
@@ -101,17 +103,13 @@ module Observed
|
|
101
103
|
prepare_rrd(rrd: rrd_path, start: t)
|
102
104
|
end
|
103
105
|
|
104
|
-
|
106
|
+
log_debug "Updating the data source '#{data_source}' with the value #{value} with timestamp #{t}"
|
105
107
|
rrd.update t, value
|
106
108
|
|
107
|
-
|
109
|
+
log_debug rrd.fetch!(:average)[-2..-1]
|
108
110
|
|
109
111
|
rrd.fetch(:average)[-2..-1].first.last
|
110
112
|
end
|
111
|
-
|
112
|
-
def logger
|
113
|
-
@logger ||= Logger.new(STDOUT)
|
114
|
-
end
|
115
113
|
end
|
116
114
|
end
|
117
115
|
end
|
data/observed-gauge.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'observed', '~> 0.
|
21
|
+
spec.add_dependency 'observed', '~> 0.2'
|
22
22
|
spec.add_dependency 'rrd-ffi', '~> 0.2.14'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
data/spec/gauge_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'observed/gauge'
|
4
|
+
require 'observed/system'
|
4
5
|
|
5
6
|
shared_examples_for 'the observed-gauge plugin' do
|
6
7
|
|
@@ -20,14 +21,13 @@ shared_examples_for 'the observed-gauge plugin' do
|
|
20
21
|
|
21
22
|
it 'reports data with averaged values' do
|
22
23
|
subject.prepare_rrd(start: t - 120, rrd: rrd)
|
23
|
-
|
24
|
-
expect {
|
25
|
-
expect {
|
26
|
-
expect { subject.report('test.foo', t, data) }.to_not raise_error
|
24
|
+
expect(subject.translate(data, {tag: 'test.foo', time: t - 120})).to be_nil
|
25
|
+
expect(subject.translate(data, {tag: 'test.foo', time: t - 60})).to be_nil
|
26
|
+
expect(subject.translate(data, {tag: 'test.foo', time: t})).to eq(expected_data)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'creates rrd files automatically on first report' do
|
30
|
-
expect { subject.
|
30
|
+
expect { subject.translate(data, {tag: 'test.foo', time: t}) }.to_not raise_error
|
31
31
|
|
32
32
|
expect { File.exist? rrd }.to be_true
|
33
33
|
end
|
@@ -64,7 +64,7 @@ describe Observed::Plugins::Gauge do
|
|
64
64
|
}
|
65
65
|
|
66
66
|
let(:system) {
|
67
|
-
sys =
|
67
|
+
sys = Observed::System.new
|
68
68
|
|
69
69
|
sys.stubs(:now).returns(t)
|
70
70
|
|
@@ -117,7 +117,7 @@ describe Observed::Plugins::Gauge do
|
|
117
117
|
}
|
118
118
|
|
119
119
|
it 'raise an error' do
|
120
|
-
expect { subject.
|
120
|
+
expect { subject.translate(data, {tag: 'test.foo', time: t}) }.to raise_error(/Unexpected type of key_path met/)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: observed-gauge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KUOKA Yusuke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: observed
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: '0.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rrd-ffi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,70 +56,70 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: mocha
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: fakefs
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
description: Gauge plugin for Observed
|
@@ -149,17 +149,17 @@ require_paths:
|
|
149
149
|
- lib
|
150
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- -
|
152
|
+
- - '>='
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0'
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.0.
|
162
|
+
rubygems_version: 2.0.3
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: A plugin to consolidate outputs from other Observed output plugins by averaging
|