Sha256: 271c424c42ca5347a88a20229ba14205aab72fef8af489d561f1f1789be6384a

Contents?: true

Size: 1.25 KB

Versions: 37

Compression:

Stored size: 1.25 KB

Contents

class Riemann::Babbler::Plugin::Net < Riemann::Babbler::Plugin

  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 init
    plugin.set_default(:service, 'net')
    plugin.set_default(:include_alias, false)
    plugin.set_default(:filter, ['rx bytes', 'rx errs', 'rx drop', 'tx bytes', 'tx errs', 'tx drop'])
  end

  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 if (iface =~ /\./ && !plugin.include_alias)
      next unless line =~ /(\w*)\:\s*([\s\d]+)\s*/
      WORDS.map do |service|
        service
      end.zip(
          $2.split(/\s+/).map { |str| str.to_i }
      ).each do |service, value|
        next unless plugin.filter.include? service
        status << { :service => "#{plugin.service} #{iface} #{service}", :metric => value.to_f/plugin.interval, :as_diff => true }
      end
    end
    status
  end

end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.8.4 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.8.3 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.8.2 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.8.1 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.8.0 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.6.0 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.9 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.8 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.7 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.6 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.5 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.4 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.3 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.2 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.1 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.5.0 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.1.5 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.1.4 lib/riemann/babbler/plugins/net.rb
riemann-babbler-2.1.3.2 lib/riemann/babbler/plugins/net.rb