collectd 0.0.12 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rst +7 -4
- data/VERSION.yml +2 -1
- data/lib/collectd/em_server.rb +0 -2
- data/lib/collectd/interface.rb +66 -50
- data/lib/collectd/server.rb +0 -2
- data/spec/interface_spec.rb +3 -1
- metadata +18 -6
data/README.rst
CHANGED
@@ -26,13 +26,16 @@ port `25826` (so it's acting as a server):
|
|
26
26
|
</Plugin>
|
27
27
|
|
28
28
|
|
29
|
-
To install the gem, make sure
|
30
|
-
RubyGems, then install it:
|
29
|
+
To install the gem, make sure the Gemcutter RubyGems server is known to your
|
30
|
+
local RubyGems, then install it:
|
31
31
|
|
32
32
|
::
|
33
33
|
|
34
|
-
gem sources -a http://
|
35
|
-
|
34
|
+
gem sources -a http://gemcutter.org
|
35
|
+
gem install collectd
|
36
|
+
|
37
|
+
Add ``sudo`` in front of the ``gem install`` command if you want it to be
|
38
|
+
installed system wide.
|
36
39
|
|
37
40
|
|
38
41
|
Usage
|
data/VERSION.yml
CHANGED
data/lib/collectd/em_server.rb
CHANGED
data/lib/collectd/interface.rb
CHANGED
@@ -140,72 +140,88 @@ module Collectd
|
|
140
140
|
@interval = interval
|
141
141
|
@counters = {}
|
142
142
|
@gauges = {}
|
143
|
+
@lock = Mutex.new
|
143
144
|
end
|
144
145
|
def set_counter(plugin_type, values)
|
145
|
-
@
|
146
|
+
@lock.synchronize do
|
147
|
+
@counters[plugin_type] = values
|
148
|
+
end
|
146
149
|
end
|
147
150
|
def inc_counter(plugin_type, values)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
151
|
+
@lock.synchronize do
|
152
|
+
old_values = @counters[plugin_type] || []
|
153
|
+
values.map! { |value|
|
154
|
+
value + (old_values.shift || 0)
|
155
|
+
}
|
156
|
+
@counters[plugin_type] = values
|
157
|
+
end
|
153
158
|
end
|
154
159
|
def set_gauge(plugin_type, values)
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
160
|
+
@lock.synchronize do
|
161
|
+
# Use count & sums for average
|
162
|
+
if @gauges.has_key?(plugin_type)
|
163
|
+
old_values = @gauges[plugin_type]
|
164
|
+
count = old_values.shift || 0
|
165
|
+
values.map! { |value| value + (old_values.shift || value) }
|
166
|
+
@gauges[plugin_type] = [count + 1] + values
|
167
|
+
else
|
168
|
+
@gauges[plugin_type] = [1] + values
|
169
|
+
end
|
163
170
|
end
|
164
171
|
end
|
165
172
|
|
166
173
|
def make_pkt
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
pkt << values
|
174
|
+
@lock.synchronize do
|
175
|
+
pkt = nil
|
176
|
+
@plugin_type_values = {}
|
177
|
+
|
178
|
+
@counters.each do |plugin_types,values|
|
179
|
+
packet_values = Packet::Values.new(values.map { |value| Packet::Values::Counter.new(value) })
|
180
|
+
populate_plugin_type_values(plugin_types, packet_values)
|
181
|
+
end
|
182
|
+
|
183
|
+
@gauges.each do |plugin_types,values|
|
184
|
+
count = values.shift || next
|
185
|
+
values.map! { |value| value.to_f / count }
|
186
|
+
packet_values = Packet::Values.new(values.map { |value| Packet::Values::Gauge.new(value) })
|
187
|
+
populate_plugin_type_values(plugin_types, packet_values)
|
188
|
+
end
|
189
|
+
|
190
|
+
pkt = [Packet::Host.new(Collectd.hostname),
|
191
|
+
Packet::Time.new(Time.now.to_i),
|
192
|
+
Packet::Interval.new(10)]
|
193
|
+
|
194
|
+
@plugin_type_values.each do |plugin,plugin_instances|
|
195
|
+
pkt << Packet::Plugin.new(plugin)
|
196
|
+
plugin_instances.each do |plugin_instance,types|
|
197
|
+
pkt << Packet::PluginInstance.new(plugin_instance)
|
198
|
+
types.each do |type,type_instances|
|
199
|
+
pkt << Packet::Type.new(type)
|
200
|
+
type_instances.each do |type_instance,values|
|
201
|
+
pkt << Packet::TypeInstance.new(type_instance)
|
202
|
+
pkt << values
|
203
|
+
end
|
198
204
|
end
|
199
205
|
end
|
200
206
|
end
|
201
|
-
end
|
202
207
|
|
203
|
-
|
204
|
-
|
208
|
+
# Reset only gauges. Counters are persistent for incrementing.
|
209
|
+
@gauges = {}
|
205
210
|
|
206
|
-
|
207
|
-
|
211
|
+
# And return serialized packet of parts
|
212
|
+
pkt.join
|
213
|
+
end
|
208
214
|
end
|
215
|
+
|
216
|
+
private
|
217
|
+
def populate_plugin_type_values(plugin_types, packet_values)
|
218
|
+
plugin, plugin_instance, type, type_instance = plugin_types
|
219
|
+
@plugin_type_values[plugin] ||= {}
|
220
|
+
@plugin_type_values[plugin][plugin_instance] ||= {}
|
221
|
+
@plugin_type_values[plugin][plugin_instance][type] ||= {}
|
222
|
+
@plugin_type_values[plugin][plugin_instance][type][type_instance] = packet_values
|
223
|
+
end
|
224
|
+
|
209
225
|
end
|
210
226
|
|
211
227
|
end
|
data/lib/collectd/server.rb
CHANGED
data/spec/interface_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
$: << File.dirname(__FILE__) + '/../lib'
|
2
2
|
require 'collectd'
|
3
3
|
|
4
|
-
describe Collectd do
|
4
|
+
describe "Collectd" do
|
5
5
|
before(:each) do
|
6
6
|
@server = mock('Server')
|
7
7
|
Collectd << @server
|
@@ -90,10 +90,12 @@ describe Collectd::ProcStats do
|
|
90
90
|
g = @server.gauges[[:plugin1, :plugin_instance1, :memory, "VmRSS"]]
|
91
91
|
g[0].should be_kind_of(Fixnum)
|
92
92
|
end
|
93
|
+
|
93
94
|
it 'should report VmSize' do
|
94
95
|
g = @server.gauges[[:plugin1, :plugin_instance1, :memory, "VmSize"]]
|
95
96
|
g[0].should be_kind_of(Fixnum)
|
96
97
|
end
|
98
|
+
|
97
99
|
end
|
98
100
|
context 'when polling cpu' do
|
99
101
|
it 'should report user time' do
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collectd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Stephan Maka
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-12-20 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -45,25 +51,31 @@ rdoc_options:
|
|
45
51
|
require_paths:
|
46
52
|
- lib
|
47
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
48
55
|
requirements:
|
49
56
|
- - ">="
|
50
57
|
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
51
61
|
version: "0"
|
52
|
-
version:
|
53
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
54
64
|
requirements:
|
55
65
|
- - ">="
|
56
66
|
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
57
70
|
version: "0"
|
58
|
-
version:
|
59
71
|
requirements: []
|
60
72
|
|
61
73
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.3.
|
74
|
+
rubygems_version: 1.3.7
|
63
75
|
signing_key:
|
64
76
|
specification_version: 3
|
65
77
|
summary: Send collectd statistics from Ruby
|
66
78
|
test_files:
|
67
79
|
- spec/interface_spec.rb
|
68
|
-
- examples/sender.rb
|
69
80
|
- examples/em_sender.rb
|
81
|
+
- examples/sender.rb
|