forked from skyscrapers/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_sidekiq_queue
executable file
·125 lines (111 loc) · 3.19 KB
/
check_sidekiq_queue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# ========================================================================================
# Sidekiq Queue Size Nagios Check
#
# (c) Wanelo Inc, Distributed under Apache License
#
# Usage:
# To check a regular queue:
# ./check_sidekiq_queue [ -h <host> ] [ -a <password> ] [ -q <default> ] [ <-n mq> ] [ -d <redis-db> ] [-w <warn_perc>] [-c <critical_perc>]
# Eg: ./check_sidekiq_queue -w 500 -c 2000 # warning at 500 or higher used, critical at 2000 or higher
#
# To check schedule or retry (system) queue:
# ./check_sidekiq_queue [ -h <host> ] [ -a <password> ] [ -s <schedule|retry> ] [ <-n mq> ] [ -d <redis-db> ] [-w <warn_perc>] [-c <critical_perc>]
#
# ========================================================================================
# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
WARNING_THRESHOLD=500
CRITICAL_THRESHOLD=1000
QUEUE="default"
SYSTEM=""
NAMESPACE=""
HOST="127.0.0.1"
PASS=""
DB=0
# Parse parameters
while [ $# -gt 0 ]; do
case "$1" in
-d | --db)
shift
DB=$1
;;
-h | --hostname)
shift
HOST=$1
;;
-a | --password)
shift
PASS=$1
;;
-q | --queue)
shift
QUEUE=$1
;;
-n | --namespace)
shift
NAMESPACE=$1
;;
-s | --system)
shift
SYSTEM=$1
;;
-w | --warning)
shift
WARNING_THRESHOLD=$1
;;
-c | --critical)
shift
CRITICAL_THRESHOLD=$1
;;
*) echo "Unknown argument: $1"
exit $STATE_UNKNOWN
;;
esac
shift
done
PATH=/opt/local/bin:$PATH
NODENAME=$HOSTNAME
ERR=/tmp/redis-cli.error.$$
rm -f $ERR
function result {
DESCRIPTION=$1
STATUS=$2
echo "SIDEKIQ $DESCRIPTION : ${NODENAME} ${QUEUE_SIZE} on ${QUEUE}|sidekiq_queue_${QUEUE}=${QUEUE_SIZE};${WARNING_THRESHOLD};${CRITICAL_THRESHOLD}"
rm -f $ERR
exit $STATUS
}
if [ "$QUEUE" != "default" -a -n "$SYSTEM" ]; then
result "CRITICAL invalid usage: pass -q or -s but not both", $STATE_CRITICAL
fi
if [ -n "$SYSTEM" -a "$SYSTEM" != "schedule" -a "$SYSTEM" != "retry" ] ; then
result "CRITICAL invalid usage: -s expect one of schedule or retry", $STATE_CRITICAL
fi
if [ ! -z "$PASS" ]; then
PASS="-a $PASS"
fi
if [ ! -z "$NAMESPACE" ]; then
NAMESPACE="$NAMESPACE:"
fi
if [ -n "$SYSTEM" ]; then
QUEUE_SIZE=`redis-cli -h $HOST $PASS -n $DB zcard ${NAMESPACE}$SYSTEM 2>$ERR | cut -d " " -f 1`
QUEUE=$SYSTEM
else
QUEUE_SIZE=`redis-cli -h $HOST $PASS -n $DB llen ${NAMESPACE}queue:$QUEUE 2>$ERR | cut -d " " -f 1`
fi
if [ -s "$ERR" ]; then
QUEUE_SIZE=`cat $ERR`
result "CRITICAL" $STATE_CRITICAL
fi
if [ $QUEUE_SIZE -ge $WARNING_THRESHOLD ] && [ $QUEUE_SIZE -lt $CRITICAL_THRESHOLD ]; then
result "WARNING" $STATE_WARNING
elif [ $QUEUE_SIZE -ge $CRITICAL_THRESHOLD ]; then
result "CRITICAL" $STATE_CRITICAL
else
result "OK" $STATE_OK
fi
# ensure that output from stderr is cleaned up
rm -f $ERR