-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_passenger_queue.sh
79 lines (71 loc) · 1.73 KB
/
check_passenger_queue.sh
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
#!/bin/sh
quit () {
echo "Passenger Queue ${1}: There are $currently_waiting waiting request(s), $max_queues maximum queues and $active_queues active queue(s)"
exit $2
}
usage () {
echo "Usage: $0 [-w|--warning WARNING_PERCENTAGE] [-c|--critical CRITICAL_PERCENTAGE] [-h|--help]"
echo "\t-w|--warning WARNING_PERCENTAGE:"
echo "\t\tThe percentage of waiting requests of the maximum amount of queues, default is 25"
echo "\t-c|--critical WARNING_PERCENTAGE:"
echo "\t\tThe percentage of waiting requests of the maximum amount of queues, default is 50"
echo "\t-h|--help:"
echo "\t\tShow this help"
}
# Check if the given option is a number
is_number () {
# is it a number?
$(expr $1 + 0 > /dev/null 2>&1)
# is it also above 0?
if [ $? -ne 0 -o $1 -le 0 ];then
echo "$1 is not a valid percentage"
exit 3
else
return 0
fi
}
# Set some defaults
W=25
C=50
# Parse options
while [ ! -z $1 ]; do
case $1 in
-w|--warning)
test -z $2 && usage; exit 3
W=$2
is_number $W
shift 2
;;
-c|--critical)
test -z $2 && usage; exit 3
C=$2
is_number $C
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 3
;;
esac
done
# Prevent footshooting
if [ $W -ge $C ]; then
echo "Warning percentage cannot be greater than or equal to Critical percentage" >&2
exit 3
fi
output=`/usr/sbin/passenger-status`
max_queues=`echo "$output" | /usr/bin/awk '/max/ { print $3 }'`
active_queues=`echo "$output" | /usr/bin/awk '/active/ { print $3 }'| head -1`
currently_waiting=`echo "$output" | /usr/bin/awk '/Waiting on global queue/ { print $5 }'`
percent="$(($currently_waiting / $max_queues * 100))"
if [ $percent -ge $C ]; then
quit "CRITICAL" 2
elif [ $percent -ge $W ]; then
quit "WARNING" 1
else
quit "OK" 0
fi