Sha256: d92218e2756a4e0bc19a9ec811b5e0bafd4611b4d1b35a28373b85fd5a06d0eb

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

#encoding: utf-8

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_bc.to_f / total)
    swap_fraction = m['SwapTotal'] == 0 ? 0 : 1 - m['SwapFree'].to_f/m['SwapTotal']

    desc = "#{shell('ps -eo pmem,pid,cmd --sort -pmem | head -10').chomp}"
    [
      { :service => plugin.service + " % free", :description => "Memory usage, %", :metric => fraction.round(2) * 100 },
      { :service => plugin.service + " % swap", :description => "Swap usage, %", :metric => swap_fraction.round(2) * 100 },
      { :service => plugin.service + " abs free", :description => "Memory free (kB)\n\n #{desc}", :metric => free, :state => 'ok' },
      { :service => plugin.service + " abs total", :description => "Memory total (kB)\n\n #{desc}", :metric => total, :state => 'ok' },
      { :service => plugin.service + " abs cached", :description => "Memory usage, cached (kB)\n\n #{desc}",  :metric => cached, :state => 'ok' },
      { :service => plugin.service + " abs buffers", :description => "Memory usage, buffers (kB)\n\n #{desc}", :metric => buffers, :state => 'ok' },
      { :service => plugin.service + " abs used", :description => "Memory usage, used (kB)\n\n #{desc}", :metric => used , :state => 'ok' },
      { :service => plugin.service + " abs free_bc", :description => "Memory usage with cache и buffers (kB)\n\n #{desc}", :metric => free_bc , :state => 'ok' }
    ]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

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