Sha256: 27f8ed2e49a5b89aa92f720db15dffe1db1abf585c163d8697dbbb1db3d810ed

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

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 * 1024
    cached =m['Cached'].to_i * 1024
    buffers =m['Buffers'].to_i * 1024
    total = m['MemTotal'].to_i * 1024
    used = total - free
    free_bc = free + buffers + cached

    fraction = 1 - (free.to_f / total)
    swap_fraction = m['SwapTotal'] == 0 ? 0 : 1 - m['SwapFree'].to_f/m['SwapTotal']

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

    [
      { :service => plugin.service + " % free", :metric => fraction },
      { :service => plugin.service + " % swap", :metric => swap_fraction },
      { :service => plugin.service + " abs free", :metric => free, :state => 'ok', :description => desc },
      { :service => plugin.service + " abs total", :metric => total, :state => 'ok', :description => desc },
      { :service => plugin.service + " abs cached", :metric => cached, :state => 'ok', :description => desc },
      { :service => plugin.service + " abs buffers", :metric => buffers, :state => 'ok', :description => desc },
      { :service => plugin.service + " abs used", :metric => used , :state => 'ok', :description => desc },
      { :service => plugin.service + " abs free_bc", :metric => free_bc , :state => 'ok', :description => desc }
    ]
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
riemann-babbler-0.7.8 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.7 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.6 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.5 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.4 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.3 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.2 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.1 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.7.0 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.9 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.8 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.7 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.6 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.5 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.4 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.3 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.2 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.1 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.6.0 lib/riemann/babbler/plugins/memory.rb
riemann-babbler-0.5.9 lib/riemann/babbler/plugins/memory.rb