Sha256: c9046a7e10f04336050c8eeefb4f951bc8477901c25ff9bc80a0262d9744936b

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# for more info check http://www.linuxhowtos.org/System/procstat.htm

class ZabbixRubyClient
  module Plugins
    module Cpu
      extend self

      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 + wait + irq + soft + steal + guest
        total = used + idle
        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}"
        back << "#{host} cpu[used] #{used}"
        back << "#{host} cpu[total] #{total}"
        return back

      end

    end
  end
end

ZabbixRubyClient::Plugins.register('cpu', ZabbixRubyClient::Plugins::Cpu)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.0.6 lib/zabbix-ruby-client/plugins/cpu.rb