Sha256: e1fddcc8772972c4a9cafa2c3f079ecff2558843c4e3c9a784f44ea343d788f3

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

# this is a simple version for standalone redis server

class ZabbixRubyClient
  module Plugins
    module Redis
      extend self

      def collect(*args)
        host = args[0]
        redis = args[1] || 'redis-cli'
        opts = args[2] || ""
        redisinfo = `#{redis} #{opts} info`
        if $?.to_i == 0
          info = get_info(redisinfo)
        else
          logger.warn "Redis connection failed."
          return []
        end

        info[:keyspace_total] = info[:keyspace_hits].to_i + info[:keyspace_misses].to_i

        time = Time.now.to_i
        back = []
        back << "#{host} redis[role] #{time} #{info[:role]}"
        back << "#{host} redis[version] #{time} #{info[:redis_version]}"
        back << "#{host} redis[used_memory] #{time} #{info[:used_memory]}"
        back << "#{host} redis[connections] #{time} #{info[:total_connections_received]}"
        back << "#{host} redis[commands] #{time} #{info[:total_commands_processed]}"
        back << "#{host} redis[hits] #{time} #{info[:keyspace_hits]}"
        back << "#{host} redis[misses] #{time} #{info[:keyspace_misses]}"
        back << "#{host} redis[total] #{time} #{info[:keyspace_total]}"
        back << "#{host} redis[changes_since_last_save] #{time} #{info[:rdb_changes_since_last_save]}"
        return back
      end

      def get_info(meat)
        ret = {}
        meat.each_line do |line|
          if line.size > 0 && line[0] != '#'
            key, value = line.split(/\:/)
            ret[key.to_sym] = value
          end
        end
        ret
      end

    end
  end
end

ZabbixRubyClient::Plugins.register('redis', ZabbixRubyClient::Plugins::Redis)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zabbix-ruby-client-0.0.15 lib/zabbix-ruby-client/plugins/redis.rb
zabbix-ruby-client-0.0.14 lib/zabbix-ruby-client/plugins/redis.rb