Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions bin/check-redis-info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,51 @@ class RedisSlaveCheck < Sensu::Plugin::Check::CLI
required: false,
default: 'master'

option :warn,
short: '-w COUNT',
long: '--warning COUNT',
description: 'COUNT warning threshold for number of items in Redis list key',
proc: proc(&:to_i),
required: false

option :crit,
short: '-c COUNT',
long: '--critical COUNT',
description: 'COUNT critical threshold for number of items in Redis list key',
proc: proc(&:to_i),
required: false

def run
redis = Redis.new(default_redis_options)

if redis.info.fetch(config[:redis_info_key].to_s) == config[:redis_info_value].to_s
ok "Redis #{config[:redis_info_key]} is #{config[:redis_info_value]}"

if config[:redis_info_value] != "master"
if redis.info.fetch(config[:redis_info_key].to_s) == config[:redis_info_value].to_s
ok "Redis #{config[:redis_info_key]} is #{config[:redis_info_value]}"
else
critical "Redis #{config[:redis_info_key]} is #{redis.info.fetch(config[:redis_info_key].to_s)}!"
end

end

length = case redis.type(config[:key])
when 'hash'
redis.hlen(config[:key])
when 'set'
redis.scard(config[:key])
else
redis.llen(config[:key])
end
if length >= config[:crit]
critical "Redis info #{config[:key]} length is above the CRITICAL limit: #{length} length / #{config[:crit]} limit"
elsif length >= config[:warn]
warning "Redis info #{config[:key]} length is above the WARNING limit: #{length} length / #{config[:warn]} limit"
else
critical "Redis #{config[:redis_info_key]} is #{redis.info.fetch(config[:redis_info_key].to_s)}!"
ok "Redis info #{config[:key]} length (#{length}) is below thresholds"
end

rescue StandardError
send(config[:conn_failure_status], "Could not connect to Redis server on #{redis_endpoint}")
end
end