lib/zabbix-ruby-client/plugins/load.rb in zabbix-ruby-client-0.0.17 vs lib/zabbix-ruby-client/plugins/load.rb in zabbix-ruby-client-0.0.18
- old
+ new
@@ -1,34 +1,41 @@
# for more info check
# http://juliano.info/en/Blog:Memory_Leak/Understanding_the_Linux_load_average
-require "zabbix-ruby-client/logger"
+require "zabbix-ruby-client/plugin_base"
module ZabbixRubyClient
module Plugins
module Load
extend self
+ extend ZabbixRubyClient::PluginBase
def collect(*args)
host = args[0]
- #cpuinfo = `mpstat | grep " all "`
- cpuinfo = `cat /proc/loadavg`
- if $?.to_i == 0
- one, five, fifteen, procs_t = cpuinfo.split(/\s+/)
+ info = get_info
+ if info
+ time = Time.now.to_i
+ back = []
+ back << "#{host} load[one] #{time} #{info[0]}"
+ back << "#{host} load[five] #{time} #{info[1]}"
+ back << "#{host} load[fifteen] #{time} #{info[2]}"
+ back << "#{host} load[procs] #{time} #{info[3]}"
+ return back
else
- Log.warn "Oh you don't have a /proc ?"
return []
end
+ end
- procs, _ = procs_t.split(/\//)
+ private
- time = Time.now.to_i
- back = []
- back << "#{host} load[one] #{time} #{one}"
- back << "#{host} load[five] #{time} #{five}"
- back << "#{host} load[fifteen] #{time} #{fifteen}"
- back << "#{host} load[procs] #{time} #{procs}"
- return back
-
+ def get_info
+ info = getline("/proc/loadavg")
+ if info
+ back = info.split(/\s+/)
+ back[3] = back[3].split(/\//)[0]
+ back
+ else
+ false
+ end
end
end
end
end