Sha256: d0ebe1ceb4ce291fc83514388c293fb8dece873b8c79ad3d444b74ae97216fd0

Contents?: true

Size: 741 Bytes

Versions: 1

Compression:

Stored size: 741 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,comm | sort -nrb -k1 | head -10').chomp}"

    [
      { :service => plugin.service, :metric => fraction },
      { :service => plugin.service + " free", :metric => free.to_f, :state => 'ok', :description => desc },
      { :service => plugin.service + " total", :metric => total.to_f, :state => 'ok', :description => desc }
    ]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

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