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 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 GitHub's RubyGems server is known to your local
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://gems.github.com
35
- sudo gem install astro-collectd
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
@@ -1,4 +1,5 @@
1
1
  ---
2
- :patch: 12
2
+ :patch: 15
3
3
  :major: 0
4
+ :build:
4
5
  :minor: 0
@@ -10,9 +10,7 @@ module Collectd
10
10
 
11
11
  EM.add_periodic_timer(interval) do
12
12
  Collectd.run_pollables_for self
13
- Thread.critical = true
14
13
  pkt = make_pkt
15
- Thread.critical = false
16
14
  begin
17
15
  @sock.send(pkt, 0)
18
16
  rescue SystemCallError
@@ -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
- @counters[plugin_type] = values
146
+ @lock.synchronize do
147
+ @counters[plugin_type] = values
148
+ end
146
149
  end
147
150
  def inc_counter(plugin_type, values)
148
- old_values = @counters[plugin_type] || []
149
- values.map! { |value|
150
- value + (old_values.shift || 0)
151
- }
152
- @counters[plugin_type] = values
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
- # Use count & sums for average
156
- if @gauges.has_key?(plugin_type)
157
- old_values = @gauges[plugin_type]
158
- count = old_values.shift || 0
159
- values.map! { |value| value + (old_values.shift || value) }
160
- @gauges[plugin_type] = [count + 1] + values
161
- else
162
- @gauges[plugin_type] = [1] + values
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
- plugin_type_values = {}
168
- @counters.each do |plugin_types,values|
169
- plugin, plugin_instance, type, type_instance = plugin_types
170
- plugin_type_values[plugin] ||= {}
171
- plugin_type_values[plugin][plugin_instance] ||= {}
172
- plugin_type_values[plugin][plugin_instance][type] ||= {}
173
- plugin_type_values[plugin][plugin_instance][type][type_instance] =
174
- Packet::Values.new(values.map { |value| Packet::Values::Counter.new(value) })
175
- end
176
- @gauges.each do |plugin_types,values|
177
- plugin, plugin_instance, type, type_instance = plugin_types
178
- plugin_type_values[plugin] ||= {}
179
- plugin_type_values[plugin][plugin_instance] ||= {}
180
- plugin_type_values[plugin][plugin_instance][type] ||= {}
181
- count = values.shift || next
182
- values.map! { |value| value.to_f / count }
183
- plugin_type_values[plugin][plugin_instance][type][type_instance] =
184
- Packet::Values.new(values.map { |value| Packet::Values::Gauge.new(value) })
185
- end
186
- pkt = [Packet::Host.new(Collectd.hostname),
187
- Packet::Time.new(Time.now.to_i),
188
- Packet::Interval.new(10)]
189
- plugin_type_values.each do |plugin,plugin_instances|
190
- pkt << Packet::Plugin.new(plugin)
191
- plugin_instances.each do |plugin_instance,types|
192
- pkt << Packet::PluginInstance.new(plugin_instance)
193
- types.each do |type,type_instances|
194
- pkt << Packet::Type.new(type)
195
- type_instances.each do |type_instance,values|
196
- pkt << Packet::TypeInstance.new(type_instance)
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
- # Reset only gauges. Counters are persistent for incrementing.
204
- @gauges = {}
208
+ # Reset only gauges. Counters are persistent for incrementing.
209
+ @gauges = {}
205
210
 
206
- # And return serialized packet of parts
207
- pkt.to_s
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
@@ -14,9 +14,7 @@ module Collectd
14
14
  sleep interval
15
15
 
16
16
  Collectd.run_pollables_for self
17
- Thread.critical = true
18
17
  pkt = make_pkt
19
- Thread.critical = false
20
18
  begin
21
19
  @sock.send(pkt, 0)
22
20
  rescue SystemCallError
@@ -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
- version: 0.0.12
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: 2009-10-12 00:00:00 +02:00
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.5
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