#!/usr/bin/env ruby # Gathers Redis SLOWLOG statistics and submits them to Riemann. require File.expand_path('../../lib/riemann/tools', __FILE__) class Riemann::Tools::RedisSlowlog include Riemann::Tools require 'redis' opt :redis_url, "Redis URL", :default => 'redis://127.0.0.1:6379/' opt :redis_password, "Redis password", :default => '' opt :slowlog_len, "Number of SLOWLOG entries to get", :default => 10 opt :slowlog_reset, "Reset SLOWLOG after querying it", :default => false def initialize @redis = ::Redis.new(url: opts[:redis_url]) @slowlog_len = opts[:slowlog_len] @slowlog_reset = opts[:slowlog_reset] @redis.auth(opts[:redis_password]) unless opts[:redis_password] == '' end def tick @redis.slowlog("GET", @slowlog_len).each do |id, timestamp, us, cmd| data = { :host => @redis.client.host, :service => "redis", :time => timestamp, :metric => us.to_f, :state => 'warning', :tags => ['redis', 'slowlog'], :description => cmd.inspect } report(data) end @redis.slowlog("RESET") if @slowlog_reset end end Riemann::Tools::RedisSlowlog.run