Module: ZabbixRubyClient::Plugins::Cpu

Extended by:
Cpu
Included in:
Cpu
Defined in:
lib/zabbix-ruby-client/plugins/cpu.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/cpu.rb', line 6

def collect(*args)
  host = args[0]
  cpuinfo = `mpstat | grep " all "`
  if $?.to_i == 0
    _, _, _, user, nice, sys, wait, irq, soft, steal, guest, idle = cpuinfo.split(/\s+/)
  else
    logger.warn "Please install sysstat."
    return []
  end
  back = []
  back << "#{host} cpu[user] #{user}"
  back << "#{host} cpu[nice] #{nice}"
  back << "#{host} cpu[system] #{sys}"
  back << "#{host} cpu[iowait] #{wait}"
  back << "#{host} cpu[irq] #{irq}"
  back << "#{host} cpu[soft] #{soft}"
  back << "#{host} cpu[steal] #{steal}"
  back << "#{host} cpu[guest] #{guest}"
  back << "#{host} cpu[idle] #{idle}"
  return back

end