Sha256: d8a2934fa67a193b9d3950e150062e4238665d17ab073c8c4a2a99c4e69c4bfd
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
class ZabbixRubyClient module Plugins module Memory extend self def collect(*args) host = args[0] meminfo = `cat /proc/meminfo` if $?.to_i == 0 info = splitinfo(meminfo) else logger.warn "Please install sysstat." return [] end mem_total = info["MemTotal"] / 1024 mem_free = (info['MemFree'] + info['Buffers'] + info['Cached']) / 1024 mem_used = mem_total - mem_free mem_percent = (mem_used / mem_total.to_f * 100).to_i swap_total = info['SwapTotal'] / 1024 swap_free = info['SwapFree'] / 1024 swap_used = swap_total - swap_free swap_percent = 0 unless swap_total == 0 swap_percent = (swap_used / swap_total.to_f * 100).to_i end time = Time.now.to_i back = [] back << "#{host} memory[total] #{time} #{mem_total}" back << "#{host} memory[used] #{time} #{mem_used}" back << "#{host} memory[free] #{time} #{mem_free}" back << "#{host} memory[percent_used] #{time} #{mem_percent}" back << "#{host} memory[swap_total] #{time} #{swap_total}" back << "#{host} memory[swap_used] #{time} #{swap_used}" back << "#{host} memory[swap_free] #{time} #{swap_free}" back << "#{host} memory[swap_percent_used] #{time} #{swap_percent}" return back end def splitinfo(info) info.split(/\n/).map(&:strip).reduce({}) do |a,line| _, key, value = *line.match(/^(\w+):\s+(\d+)\s/) a[key] = value.to_i a end end end end end ZabbixRubyClient::Plugins.register('memory', ZabbixRubyClient::Plugins::Memory)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zabbix-ruby-client-0.0.11 | lib/zabbix-ruby-client/plugins/memory.rb |