Sha256: 6762be51a3b055ba7549aa940417ce4c86bd4e06ad872a81a82fce87f4e95048

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

# 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
    module Load
      extend self
      extend ZabbixRubyClient::PluginBase

      def collect(*args)
        host = args[0]
        info = get_info
        if info
          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
          return []
        end
      end

    private

      def get_info
        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

    end
  end
end

ZabbixRubyClient::Plugins.register('load', ZabbixRubyClient::Plugins::Load)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.1.3 lib/zabbix-ruby-client/plugins/load.rb