Sha256: 0127fc834f7eccc120fb8e240a08c222c5542f4ce1a7172cc1cce117df6da6b3

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

# for more info check 
# http://www.linuxhowtos.org/System/procstat.htm
# http://juliano.info/en/Blog:Memory_Leak/Understanding_the_Linux_load_average
require "zabbix-ruby-client/logger"

module ZabbixRubyClient
  module Plugins
    module Cpu
      extend self

      def collect(*args)
        host = args[0]
        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
          Log.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

    end
  end
end

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

Version data entries

2 entries across 2 versions & 1 rubygems

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