-
Notifications
You must be signed in to change notification settings - Fork 57
/
check_rabbitmq-ack-rate
executable file
·223 lines (197 loc) · 7.81 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/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 threshold of ack rate, defaults to '10'.
--critical|-c : The critical thresholdof ack rate, defaults to '5'.
--queue-warning|-qw : The amount of unprocessed messages in the queue before generating a warning, defaults to '50'. A negative number turns off this check.
--queue-critical|-qc : The amount of unprocessed messages in the queue before generation a critical, defaults to '100'. A negative number turns off this check.
--priority-queue|-pc : The queue defined by -q|--queue is not checked and the check is green if the priority queue is NOT empty.
--debug|-d : Show debug values, aka echo some params
Example usage:
./check_rabbitmq_ack_rate -q incoming -u stats -p strongpw
eof
exit 3
}
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=5; fi
if [[ -z "${queue_processing_rate_warning}" ]]; then queue_processing_rate_warning=10; 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
$debug && echo "Debug: curl -s -u ${user}:${passwd} http://${url}/api/queues${vhost}"
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
if [[ -n "${priority_queue_name}" ]];then
priority_queue_messages=$( echo $get | jq ". | map(select(.name == \"${priority_queue_name}\")) | .[].messages" -r )
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_messages_ack_rate}" == 'null' ]] && queue_messages_ack_rate=0
[[ "${queue_messages_get_rate}" == 'null' ]] && queue_messages_get_rate=0
[[ "${queue_messages_noack_rate}" == 'null' ]] && queue_messages_noack_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"
if [[ -n "${priority_queue_name}" ]];then
echo "Debug: messages in the priority queue '${priority_queue_name}': $priority_queue_messages"
fi
fi
}
do_main_check () {
# Check if queue_messages is not empty
if [[ -z "${queue_messages}" ]];then
message="Critical: The queue '${queue_name}' doesn't seem to exist."
exitstatus=2
quit
fi
if [[ -n "${priority_queue_name}" ]];then
# Check if there are messages in the priority queue (including unacked messages)
if (( $( echo "${priority_queue_messages} > 0" | bc -l ) ));then
message="Ok: The queue with higher priority '${priority_queue_name}' is not empty so the queue '${queue_name}' can grow."
exitstatus=0
quit
fi
fi
# 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
message="Ok: The queue '${queue_name}' has no new messages to process. The current ack rate is ${queue_messages_ack_rate}m/s."
exitstatus=0
quit
fi
# There has to be some messages to process before we check the ack rate
if (( $( echo "${queue_messages} > ${queue_processing_rate_warning}" | bc -l ) ));then
if (( $( echo "${queue_messages_ack_rate} < ${queue_processing_rate_critical}" | bc -l ) ));then
message="Critical: The queue '${queue_name}' is acking messages too slowly at ${queue_messages_ack_rate}m/s, messages in the queue: '${queue_messages}'."
exitstatus=2
quit
fi
if (( $( echo "${queue_messages_ack_rate} < ${queue_processing_rate_warning}" | bc -l ) ));then
message="Warning: The queue '${queue_name}' is acking messages too slowly at ${queue_messages_ack_rate}m/s, messages in the queue: '${queue_messages}'."
exitstatus=1
# do not quit yet because the check still can be critical, see the following check below
fi
fi
# Check the total number of messages
if (( $( echo "${queue_messages} > ${queue_messages_critical}" | bc -l ) )) && (( "${queue_messages_critical}" >= 0 ));then
message="Critical: The queue '${queue_name}' is filling up. Ack rate: ${queue_messages_ack_rate}m/s, messages in the queue: '${queue_messages}'."
exitstatus=2
quit
elif (( $( echo "${queue_messages} > ${queue_messages_warning}" | bc -l ) )) && (( "${queue_messages_warning}" >= 0 ));then
message="Warning: The queue '${queue_name}' is filling up. Ack rate: ${queue_messages_ack_rate}m/s, messages in the queue: '${queue_messages}'."
exitstatus=1
quit
fi
if [[ $exitstatus != 1 ]];then
message="Ok: The queue '${queue_name}' is acking messages at ${queue_messages_ack_rate}m/s, messages in the queue: '${queue_messages}'."
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_critical=$1
shift
;;
--queue-warning|-qw)
shift
queue_messages_warning=$1
shift
;;
--queue-critical|-qc)
shift
queue_messages_critical=$1
shift
;;
--priority-queue|-pc)
shift
priority_queue_name=$1
shift
;;
--debug|-d)
shift
debug=true
;;
*)
showhelp
;;
esac
done
defaults
data
do_main_check
quit