-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from inkel/redis-slowlog-client
Add a Redis SLOWLOG client
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |