lib/riemann/babbler/plugins/net.rb in riemann-babbler-1.1.0pre2 vs lib/riemann/babbler/plugins/net.rb in riemann-babbler-1.1.6

- old
+ new

@@ -1,16 +1,36 @@ class Riemann::Babbler::Net < 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'] + def collect f = File.read('/proc/net/dev') status = Array.new f.split("\n").each do |line| iface = line.split(':')[0].strip iface.gsub!(/\./, '_') next unless line =~ /(\w*)\:\s*([\s\d]+)\s*/ - status << { :service => "#{plugin.service} #{iface} bytes out", :metric => SysInfo::Net.out(iface, 'bytes'), :as_diff => true } - status << { :service => "#{plugin.service} #{iface} bytes in", :metric => SysInfo::Net.in(iface, 'bytes'), :as_diff => true } - status << { :service => "#{plugin.service} #{iface} bytes errors", :metric => SysInfo::Net.total(iface, 'errors'), :state => 'ok' } + WORDS.map do |service| + "#{plugin.service} #{iface} #{service}" + end.zip( + $2.split(/\s+/).map { |str| str.to_i } + ).each do |service, value| + status << { :service => service, :metric => value, :as_diff => true} + end end status end end