Sha256: 9b61987dfd5e83d5ec41e98d7b924fdaadbb8b96e5104daa74c24c3762de7a22

Contents?: true

Size: 964 Bytes

Versions: 7

Compression:

Stored size: 964 Bytes

Contents

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']

  def plugin
    options.plugins.net
  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*/
        iface = $1
        WORDS.map do |service|
          "#{plugin.service} #{iface} #{service}"
        end.zip(
          $2.split(/\s+/).map { |str| str.to_i }
        ).each do |service, value|
          status.merge!({service => value})
        end
      end
    end
    return status
  end

  def tick
    net.each do |service, value|
    report({
      :service => service,
      :metric => value
    })
    end
  end

end

Riemann::Babbler::Net.run

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
riemann-babbler-0.1.2 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.1.1 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.1.0 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.0.9 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.0.8 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.0.7 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.0.6 lib/riemann/babbler/plugins/net.rb