lib/riemann/babbler/plugins/net.rb in riemann-babbler-0.1.2 vs lib/riemann/babbler/plugins/net.rb in riemann-babbler-0.1.3
- old
+ new
@@ -1,28 +1,33 @@
class Riemann::Babbler::Net
include Riemann::Babbler
WORDS = ['rx bytes',
- 'rx packets',
- 'rx errs',
- 'rx drop',
- 'rx fifo',
- 'rx frame',
- 'rx compressed',
- 'rx multicast',
- 'tx bytes',
- 'tx packets',
- 'tx drops',
- 'tx fifo',
- 'tx colls',
- 'tx carrier',
- 'tx compressed']
+ 'rx packets',
+ 'rx errs',
+ 'rx drop',
+ 'rx fifo',
+ 'rx frame',
+ 'rx compressed',
+ 'rx multicast',
+ 'tx bytes',
+ 'tx packets',
+ 'tx drops',
+ 'tx fifo',
+ 'tx colls',
+ 'tx carrier',
+ 'tx compressed']
def plugin
options.plugins.net
end
+ def init
+ @diff = Hash.new
+ @old_status = Hash.new
+ end
+
def net
f = File.read('/proc/net/dev')
status = Hash.new
f.split("\n").inject({}) do |s, line|
if line =~ /\s*(\w+?):\s*([\s\d]+)\s*/
@@ -34,19 +39,21 @@
).each do |service, value|
status.merge!({service => value})
end
end
end
- return status
+ status.each_key { |key| @diff[key] = status[key] - @old_status[key] } if @old_status
+ @old_status = status
+ @diff
end
def tick
net.each do |service, value|
- report({
- :service => service,
- :metric => value
- })
- end
+ report({
+ :service => service,
+ :metric => value
+ })
+ end unless net.nil?
end
end
Riemann::Babbler::Net.run