Sha256: cd3160f4097861481f170cb3ec96fdce92fea67920dde6db85dd8f7318a521b9

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

class Riemann::Babbler::Memory < Riemann::Babbler

  def collect
    m = File.read('/proc/meminfo').split(/\n/).inject({}) { |info, line|
      x = line.split(/:?\s+/)
      info[x[0]] = x[1].to_i
      info
    }
    free = m['MemFree'].to_i + m['Buffers'].to_i + m['Cached'].to_i
    total = m['MemTotal'].to_i
    fraction = 1 - (free.to_f / total)

    desc = "usage\n\n#{shell('ps -eo pmem,pid,cmd | sort -nrb -k1 | head -10').chomp}"

    [
      { :service => plugin.service + " free_%+Buffers+Cached", :metric => fraction },
      { :service => plugin.service + " swap_%", :metric => (m['SwapTotal'] - m['SwapFree']).to_f/m['SwapTotal'] },
      { :service => plugin.service + " free", :metric => free.to_i, :state => 'ok', :description => desc },
      { :service => plugin.service + " total", :metric => total.to_i, :state => 'ok', :description => desc }
    ]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-babbler-0.5.0 lib/riemann/babbler/plugins/memory.rb