Sha256: 8d4a015c18375866cb9043de9db9ec1ee8e785b874ea988539ddfc6ba6eb2931

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

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 init
    @old_status = Hash.new
  end

  def net
    f = File.read('/proc/net/dev')
    status = Hash.new
    @diff = Hash.new
    f.split("\n").each do |line|
      iface = line.split(":")[0].strip
      iface.gsub!(/\./,"_")
      next unless line =~ /(\w*)\:\s*([\s\d]+)\s*/
      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
    status.each_key { |key| @diff.merge!({key => status[key] - @old_status[key]}) } unless @old_status.empty?
    @old_status = status
    @diff
  end

  def tick
    status = net
    status.each_key do |service|
      #next if status[service] == 0
      report({
        :service => service,
        :metric => status[service]
      })
    end
  end

end

Riemann::Babbler::Net.run

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
riemann-babbler-0.2.0 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.1.9 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.1.8 lib/riemann/babbler/plugins/net.rb
riemann-babbler-0.1.7 lib/riemann/babbler/plugins/net.rb