lib/zabbix-ruby-client/plugins/load.rb in zabbix-ruby-client-0.1.2 vs lib/zabbix-ruby-client/plugins/load.rb in zabbix-ruby-client-0.1.3

- old
+ new

@@ -1,6 +1,6 @@ -# for more info check +# for more info check # http://juliano.info/en/Blog:Memory_Leak/Understanding_the_Linux_load_average require "zabbix-ruby-client/plugin_base" module ZabbixRubyClient module Plugins @@ -10,11 +10,10 @@ def collect(*args) host = args[0] 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]}" @@ -25,13 +24,25 @@ end private def get_info - info = getline("/proc/loadavg") - if info - back = info.split(/\s+/) - back[3] = back[3].split(/\//)[0] + case os + when :linux + info = getline("/proc/loadavg") + if info + back = info.split(/\s+/) + back[3] = back[3].split(/\//)[0] + back + else + false + end + when :unix + output = `uptime | awk '{print $(NF-2)" "$(NF-1)" "$(NF-0)}' | tr "," " "` + back = output.split(/\s+/) + procs = `top -n | grep processes` + data = procs.split(/\s+/) + back << data[2] back else false end end