#!/usr/bin/env ruby # Gathers redis INFO statistics and submits them to Riemann. require File.expand_path('../../lib/riemann/tools', __FILE__) class Riemann::Tools::Redis include Riemann::Tools require 'redis' opt :redis_host, "Redis hostname", :default => 'localhost' opt :redis_port, "Redis port", :default => 6379 opt :redis_password, "Redis password", :default => '' opt :redis_url, "Redis URL", :default => '' opt :redis_socket, "Redis socket", :default => '' opt :redis_section, "Redis INFO section", :default => 'default' STRING_VALUES = %w{ redis_version redis_git_sha1 redis_mode os multiplexing_api gcc_version run_id used_memory_human used_memory_peak_human mem_allocator rdb_last_bgsave_status aof_last_bgrewrite_status role } def initialize options = if opts[:redis_url] != '' { :url => opts[:redis_url] } elsif opts[:redis_socket] != '' { :path => opts[:redis_socket] } else { :host => opts[:redis_host], :port => opts[:redis_port] } end @redis = ::Redis.new(options) @redis.auth(opts[:redis_password]) unless opts[:redis_password] == '' @section = opts[:redis_section] end def tick @redis.info(@section).each do |property, value| data = { :host => opts[:redis_host], :service => "redis #{property}", :metric => value.to_f, :state => 'ok', :tags => ['redis'] } if STRING_VALUES.include?(property) || property.match(/^db\d+/) if %w{ rdb_last_bgsave_status aof_last_bgrewrite_status }.include?(property) data[:state] = value else data[:description] = value end end report(data) end end end Riemann::Tools::Redis.run