From 597cb9f57e68487037dd3e58a8e14ae6c029d0ce Mon Sep 17 00:00:00 2001 From: Yuri Kudryavtsev Date: Wed, 16 Oct 2019 16:50:41 +0300 Subject: [PATCH] added -w and -c options to check --- bin/check-redis-info.rb | 42 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/bin/check-redis-info.rb b/bin/check-redis-info.rb index 881deb8..403d28d 100755 --- a/bin/check-redis-info.rb +++ b/bin/check-redis-info.rb @@ -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 +