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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zabbix-ruby-client/plugins/cpu.rb', line 10

def collect(*args)
  host = args[0]
  #cpuinfo = `mpstat | grep " all "`
  cpuinfo = `cat /proc/stat | grep "^cpu"`
  if $?.to_i == 0
    _, user, nice, sys, idle, wait, irq, soft, guest, steal = cpuinfo.split(/\s+/).map(&:to_i)
  else
    logger.warn "Oh you don't have a /proc ?"
    return []
  end
  used = user + nice + sys
  total = used + idle

  time = Time.now.to_i
  back = []
  back << "#{host} cpu[user] #{time} #{user}"
  back << "#{host} cpu[nice] #{time} #{nice}"
  back << "#{host} cpu[system] #{time} #{sys}"
  back << "#{host} cpu[iowait] #{time} #{wait}"
  back << "#{host} cpu[irq] #{time} #{irq}"
  back << "#{host} cpu[soft] #{time} #{soft}"
  back << "#{host} cpu[steal] #{time} #{steal}"
  back << "#{host} cpu[guest] #{time} #{guest}"
  back << "#{host} cpu[idle] #{time} #{idle}"
  back << "#{host} cpu[used] #{time} #{used}"
  back << "#{host} cpu[total] #{time} #{total}"
  return back

end