Skip to content

Commit

Permalink
Merge pull request #30 from inkel/redis-slowlog-client
Browse files Browse the repository at this point in the history
Add a Redis SLOWLOG client
  • Loading branch information
aphyr committed Apr 2, 2013
2 parents 4b69d9d + e00fd81 commit a1d3e76
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions bin/riemann-redis-slowlog
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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

0 comments on commit a1d3e76

Please sign in to comment.