Sha256: 6b0bb4d7b5bd14460881a834b1a911c1cb98ec2b12efff4206e250b3a2ea2a1b

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

class ZabbixRubyClient
  module Plugins
    module Memory
      extend self

      def collect(*args)
        host = args[0]
        meminfo = `vmstat -s | head -10`
        if $?.to_i == 0
          info = splitinfo(meminfo)
        else
          logger.warn "Please install sysstat."
          return []
        end
        back = []
        back << "#{host} memory[total] #{info["totalmemory"]}"
        back << "#{host} memory[used] #{info["usedmemory"]}"
        back << "#{host} memory[active] #{info["activememory"]}"
        back << "#{host} memory[inactive] #{info["inactivememory"]}"
        back << "#{host} memory[free] #{info["freememory"]}"
        back << "#{host} memory[buffer] #{info["buffermemory"]}"
        back << "#{host} memory[swap_cache] #{info["swapcache"]}"
        back << "#{host} memory[swap_total] #{info["totalswap"]}"
        back << "#{host} memory[swap_used] #{info["usedswap"]}"
        back << "#{host} memory[swap_free] #{info["freeswap"]}"
        return back
      end

      def splitinfo(info)
        info.split(/\n/).map(&:strip).reduce({}) do |a,line|
          kb, _, label1, label2 = line.split(" ")
          a[label1+label2] = kb
          a
        end
      end

    end
  end
end

ZabbixRubyClient::Plugins.register('memory', ZabbixRubyClient::Plugins::Memory)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.0.5 lib/zabbix-ruby-client/plugins/memory.rb
zabbix-ruby-client-0.0.4 lib/zabbix-ruby-client/plugins/memory.rb