Skip to content

Instantly share code, notes, and snippets.

@gardenmwm
Created July 16, 2015 23:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gardenmwm/da0046a22d9ac3b06ccf to your computer and use it in GitHub Desktop.
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
@davidlwillson
Copy link

Going to using this. Thanks.

@davidlwillson
Copy link

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.

@davidlwillson
Copy link

[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