Monitoring RabbitMQ queues but handle no queue situation

Written by - 0 comments

Published on - Listed in Monitoring Perl Coding


A while ago, it's been two years already, I improved the check_rabbitmq_queue and fixed a bug in this Perl coded Monitoring Plugin.

Now I ran into another issue with RabbitMQ queue monitoring: The situation of no defined queues.

No queues are defined in RabbitMQ

No queues = Empty array

When the monitoring plugin is executed against a target RabbitMQ server (here running on localhost) without any queues, the plugin exits with an UNKNOWN error: 

ck@rmq:~$ /usr/lib/nagios/plugins/check_rabbitmq_queue.pl -H 127.0.0.1 -u user -p secret --verbose
Illegal division by zero at /usr/lib/nagios/plugins/check_rabbitmq_queue.pl line 197.

How do I know, that no queues are defined? There are two ways.

First using the rabbitmqctl command, which can be executed as root user:

root@rmq:~# rabbitmqctl list_queues
Timeout: 60.0 seconds ...
Listing queues for vhost / ...

Second - and this is used by the monitoring plugin the background - is by using the RabbitMQ API:

ck@rmq:~$ curl http://localhost:15672/api/queues -u user:secret
[]

An empty array is the response from the API. This means on this RabbitMQ server there are (currently) no queues defined.

Handling the no queue situation

I slightly modified the Perl code right after the plugin handles the response from the API. In order to catch the empty array, the array itself needs to be converted to a scalar variable and the number of elements are then read. Obviously if the number of elements inside this array is 0 (zero), then we're having this empty array (no queues) situation.

159 my $url = "";
160 if ($queue eq "all"){
161     $url = sprintf("http%s://%s:%d/api/queues%s", ($p->opts->ssl ? "s" : ""), $hostname, $port, $vhost);
162 } else{
163     $url = sprintf("http%s://%s:%d/api/queues%s/%s", ($p->opts->ssl ? "s" : ""), $hostname, $port, $vhost, $queue);
164 }
165 my ($retcode, $result) = request($url);
166 
167 # Handle empty queue list
168 if ($retcode == 200) {
169     $result =~ s/^\s+|\s+$//g;
170     if (ref($result) eq 'ARRAY' && scalar(@$result) == 0) {
171         $p->nagios_exit(UNKNOWN, "No queues found on RabbitMQ");
172     }
173 }

174 if ($retcode == 404 && $ignore) {
175     $p->nagios_exit(OK, "$result : $url");
176 }
177 if ($retcode != 200) {
178     $p->nagios_exit(CRITICAL, "$result : $url");
179 }
180 
181 my @values = ();
182 my @metrics = ("messages", "messages_ready", "messages_unacknowledged", "consumers");

New plugin output: No queues found

With that change, the plugin will now exit with state UNKNOWN (exit 3) and show in the output why: Because no queues were discovered on this RabbitMQ server.

ck@rmq:~$ ./check_rabbitmq_queue.pl -H 127.0.0.1 -u user -p secret --verbose
RABBITMQ_QUEUE UNKNOWN - No queues found on RabbitMQ

Plugin changes published

These changes have been published upstream, although the original upstream project is unfortunately dead. I also made the changes available in a new version (2.0.4) of check_rabbitmq_queue.pl in my fork on GitHub


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Observability   Office   OpenSearch   PHP   Perl   Personal   PostgreSQL   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Znuny   Zoneminder