Module: ZabbixRubyClient::Plugins::Memory

Extended by:
Memory
Included in:
Memory
Defined in:
lib/zabbix-ruby-client/plugins/memory.rb

Instance Method Summary collapse

Instance Method Details

#collect(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zabbix-ruby-client/plugins/memory.rb', line 6

def collect(*args)
  host = args[0]
  meminfo = `vmstat -s | head -10`
  if $?.to_i == 0
    info = splitinfo(meminfo)
  else
    logger.warn "Please install sysstat."
    return []
  end
  back = []
  back << "#{host} memory[total] #{info["totalmemory"]}"
  back << "#{host} memory[used] #{info["usedmemory"]}"
  back << "#{host} memory[active] #{info["activememory"]}"
  back << "#{host} memory[inactive] #{info["inactivememory"]}"
  back << "#{host} memory[free] #{info["freememory"]}"
  back << "#{host} memory[buffer] #{info["buffermemory"]}"
  back << "#{host} memory[swap_cache] #{info["swapcache"]}"
  back << "#{host} memory[swap_total] #{info["totalswap"]}"
  back << "#{host} memory[swap_used] #{info["usedswap"]}"
  back << "#{host} memory[swap_free] #{info["freeswap"]}"
  return back
end

#splitinfo(info) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/zabbix-ruby-client/plugins/memory.rb', line 29

def splitinfo(info)
  info.split(/\n/).map(&:strip).reduce({}) do |a,line|
    kb, _, label1, label2 = line.split(" ")
    a[label1+label2] = kb
    a
  end
end