-
Notifications
You must be signed in to change notification settings - Fork 56
/
check_rabbitmq-ack-rate
executable file
·201 lines (187 loc) · 7.11 KB
/
check_rabbitmq-ack-rate
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
#
# Author: Bart Janssens
# Email: bjanssens@inuits.eu
# Date: Wed Apr 6 2016
#
# Requires the jq package to work
#
showhelp () {
cat <<eof
Check to see if a rabbitmq queue is behaving like it should.
This will do a curl to get details on the queue.
Then it will parse the data from the curl by using jq.
Parameters:
--queue|-q : The queue to check
--vhost|-v : The vhost to check
--help|-h : Shows help
--passwd|-p : The password of the user, defaults to 'guest'
--user|-u : The user to use, defaults to 'guest'
--url : The url to use, format 'host : port' defaults to 'localhost : 15672'
--warning|-w : The warning threashold, defaults to '0.5'. This is the relationship between messages acked vs messages acked
--critical|-c : The critical threashold, defaults to '0.3'. This is the relationship between messages acked vs messages acked
--queue-warning|-qw : The amount of unprocessed messages in the queue before generating a warning
--queue-critical|-qc : The amount of unprocessed messages in the queue before the check goes critical.
--debug|-d : Show debug values, aka echo some params
Example usage:
./check_rabbitmq_ack_rate -q incoming -u stats -p strongpw
eof
exit 3
}
function devide() {
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null)
echo $result
}
defaults () {
float_scale='2'
# Required params
if [[ -z "${queue_name}" ]]; then message="Unknown: You need to specify, --queue or use --help."; exitstatus='3'; quit; fi
# Optional params
if [[ -z "${debug}" ]]; then debug=false; fi
if [[ -z "${passwd}" ]]; then passwd='guest'; fi
if [[ -z "${queue_processing_rate_critical}" ]]; then queue_processing_rate_critical='0.3'; fi
if [[ -z "${queue_processing_rate_warning}" ]]; then queue_processing_rate_warning='0.5'; fi
if [[ -z "${user}" ]]; then user='guest'; fi
if [[ -z "${url}" ]]; then url='localhost:15672'; fi
if [[ -z "${vhost}" ]]; then vhost=''; fi
if [[ -z "${queue_messages_warning}" ]]; then queue_messages_warning='50'; fi
if [[ -z "${queue_messages_critical}" ]]; then queue_messages_critical='100'; fi
}
data () {
# Validations
if [[ -n "$vhost" ]] && [[ "${vhost:0:1}" != "/" ]]; then vhost="/${vhost}"; fi
# Get the data
if $debug; then echo "Debug: curl -s -u ${user}:${passwd} http://${url}/api/queues${vhost}"; fi
get=$( curl -s -u ${user}:${passwd} http://${url}/api/queues${vhost} )
# Parse the data
queue_error=$( echo $get | jq "." | grep 'error' )
if [[ ! -z "${queue_error}" ]]; then message="Unknown: curl error:${queue_error} ."; exitstatus='3'; quit; fi
queue_messages=$( echo $get | jq ". | map(select(.name == \"${queue_name}\")) | .[].messages" -r )
queue_messages_unack=$( echo $get | jq ". | map(select(.name == \"${queue_name}\")) | .[].messages_unacknowledged" -r )
queue_messages_delta=$( echo $get_delta_one | jq ". | map(select(.name == \"${queue_name}\")) | .[].messages" -r )
queue_messages_ack_rate=$( echo $get | jq ". | map(select(.name == \"${queue_name}\")) | .[].message_stats.ack_details.rate" -r )
queue_messages_get_rate=$( echo $get | jq ". | map(select(.name == \"${queue_name}\")) | .[].message_stats.get_details.rate" -r )
queue_messages_noack_rate=$( echo $get | jq ". | map(select(.name == \"${queue_name}\")) | .[].message_stats.ack_details.rate" -r )
queue_processing_rate='0'
# Check the data
if $debug
then
echo "Debug: messages: $queue_messages"
echo "Debug: messages unack: $queue_messages_unack"
echo "Debug: messages ack: $queue_messages_ack_rate"
echo "Debug: messages get: $queue_messages_get_rate"
echo "Debug: messages noack: $queue_messages_noack_rate"
fi
}
do_main_check () {
# Check if there are messages in the queue minus the unacked messages as we don't care about those
queue_messages=$(( ${queue_messages} - ${queue_messages_unack} ))
if (( $( echo "${queue_messages} > 0" | bc -l ) ))
then
# If that is the case, check that the ack rate isn't 0
if [[ ! "$queue_messages_ack_rate" == "0" ]]
then
# Calculate the processing rate
queue_processing_rate=$( devide "${queue_messages_get_rate} / ${queue_messages_ack_rate}" )
if $debug
then
echo "Debug: messages processing: $queue_processing_rate"
fi
# Check the processing rate against the given threasholds
if (( $( echo "${queue_processing_rate} < ${queue_processing_rate_critical}" | bc -l ) )) && (( $echo "${queue_messages} > ${queue_messages_critical}" | bc -l ))
then
message=$( echo "Critical: Queue '${queue_name}' is processing messages at ${queue_processing_rate}/s, messages in the queue: '${queue_messages}'." )
exitstatus='2'
elif (( $( echo "${queue_processing_rate} < ${queue_processing_rate_warning}" | bc -l ) )) && (( $echo "${queue_messages} > ${queue_messages_warning}" | bc -l ))
then
message=$( echo "Warning: Queue '${queue_name}' is processing messages at ${queue_processing_rate}/s, messages in the queue: '${queue_messages}'." )
exitstatus='1'
else
message=$( echo "OK: Queue '${queue_name}' is processing messages at ${queue_processing_rate}/s." )
exitstatus='0'
fi
# If the ack rate is 0, we have an issue.
else
# Check to see if the amount of messages in the queue isn't generating a false positive,
# like 1 that just hasn't been picked up yet
if (( $echo "${queue_messages} > ${queue_messages_critical}" | bc -l ))
then
message=$( echo "Critical: Queue '${queue_name}' is NOT acking messages, messages in the queue: '${queue_messages}'." )
exitstatus='2'
elif (( $echo "${queue_messages} > ${queue_messages_warning}" | bc -l ))
then
message=$( echo "Warning: Queue '${queue_name}' is NOT acking messages, messages in the queue: '${queue_messages}'." )
exitstatus='1'
else
message=$( echo "Ok: Queue '${queue_name}' is NOT acking messages, messages in the queue: '${queue_messages}'." )
exitstatus='0'
fi
fi
else
message=$( echo "Ok: Queue '${queue_name}' is idle" )
exitstatus='0'
fi
}
quit () {
echo "${message}" && exit $exitstatus
}
# start the case-ing
while test -n "$1"
do
case "$1" in
--help|-h)
showhelp
;;
--queue|-q)
shift
queue_name=$1
shift
;;
--user|-u)
shift
user=$1
shift
;;
--passwd|-p)
shift
passwd=$1
shift
;;
--vhost|-v)
shift
vhost=$1
shift
;;
--warning|-w)
shift
queue_processing_rate_warning=$1
shift
;;
--critical|-c)
shift
queue_processing_rate_ciritical=$1
shift
;;
--queue-warning|-qw)
shift
queue_messages_warning=$1
shift
;;
--queue-critical|-qc)
shift
queue_messages_critical=$1
shift
;;
--debug|-d)
shift
debug=true
;;
*)
showhelp
;;
esac
done
defaults
data
do_main_check
quit