Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Quick script for checking size of a redis queue
#!/bin/bash
# nagios plugin check_redisqueue
#
# check size of redis queue, doesn't use option flags, so
# check_redisqueue <queuename> <warn> <crit>
# If you don't want graphite set below to 0
#command vars
SENDTOGRAPHITE=1
GRAPHITEHOST=localhost
GRAPHITEPORT=2003
#nagios const
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
#init, also usefull for testing
RETURN=$STATE_CRITICAL
OUTPUT="$0 executing with args $1 $2 $3 "
QUEUELENGTH=`redis-cli llen $1 | cut -f2`
if [[ $QUEUELENGTH -le $2 ]]; then
RETURN=$STATE_OK
OUTPUT="OK: $QUEUELENGTH"
elif [[ $QUELENGTH -le $3 ]]; then
RETURN=$STATE_WARNING
OUTPUT="WARNING: $QUEUELENGTH"
else
RETURN=$STATE_CRITICAL
OUTPUT="PROBLEM: Error"
fi
if [[ SENDTOGRAPHITE -eq 1 ]]; then
echo "services.redis.queue.$1.length $QUEUELENGTH `date +%s`" | nc ${GRAPHITEHOST} ${GRAPHITEPORT}
fi
#plugin output and return code
echo $OUTPUT
exit $RETURN

barahon commented Oct 15, 2015

Going to using this. Thanks.

barahon commented Oct 20, 2015

Found a mis-spelled variable and it doesn't return the metric on critical.

Do you have this in a repo? I can do a pull request.

barahon commented Oct 20, 2015

[dlwillson@nb-willson-7 etc]$ git diff 64da636d24e3b068e30fd32701b35c1fb9e29f30
diff --git a/etc/redis/check_redisqueue b/etc/redis/check_redisqueue
index 5823472..c596348 100755
--- a/etc/redis/check_redisqueue
+++ b/etc/redis/check_redisqueue
@@ -29,13 +29,15 @@ QUEUELENGTH=$( redis-cli llen $1 | cut -f2 )
 if [[ $QUEUELENGTH -le $2 ]]; then
        RETURN=$STATE_OK
        OUTPUT="OK: $QUEUELENGTH"
-
-elif [[ $QUELENGTH -le $3 ]]; then
+elif [[ $QUEUELENGTH -le $3 ]]; then
        RETURN=$STATE_WARNING
        OUTPUT="WARNING: $QUEUELENGTH"
-else
+elif [[ $QUEUELENGTH -gt $3 ]]; then
        RETURN=$STATE_CRITICAL
-       OUTPUT="PROBLEM: Error"
+       OUTPUT="CRITICAL: $QUEUELENGTH"
+else
+       RETURN=$STATE_UNKNOWN
+       OUTPUT="UNKNOWN: Error"
 fi

 if [[ SENDTOGRAPHITE -eq 1 ]]; then
[dlwillson@nb-willson-7 etc]$ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment