Monitoring RabbitMQ Queues with Zabbix
Sun 09 October 2011 by tvdRecently I setup some monitoring on a RabbitMQ server using Zabbix. This process is by no means difficult, but I thought it was worth sharing.
I was looking for a solution that did not require additional plugins or packages, but would perform well. Some useful tools for monitoring include: the Management Plugin for RabbitMQ - works well, but provides more info than I needed; SNMP Statistics Plugin which looks promising; and the method below.
This assumes a zabbix server and agent(s) are setup, and a basic knowledge of zabbix.
Zabbix User Parameters
These user parameters pull all of the queue and exchange information out of rabbitmqctl for a particular queue and exchange.
I created a new file, /etc/zabbix/zabbix.conf.d/rabbitmq-server-stats.conf, which looked like the one below. It assumes rabbitmqctl is at /usr/sbin/rabbitmqctl.
#
# Meta params.
#
UserParameter=batch.queues,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_queues | grep -cv '\.\.\.'
UserParameter=batch.exchanges,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_exchanges | grep -cv '\.\.\.'
#
# some-queue statistics.
#
UserParameter=batch.queue.durable,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_queues name durable | grep 'some-queue' | awk '{ print $2 }'
UserParameter=batch.queue.msg_ready,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_queues name messages_ready | grep 'some-queue' | awk '{ print $2 }'
UserParameter=batch.queue.msg_unackd,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_queues name messages_unacknowledged | grep 'some-queue' | awk '{ print $2 }'
UserParameter=batch.queue.msgs,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_queues name messages | grep 'some-queue' | awk '{ print $2 }'
UserParameter=batch.queue.consumers,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_queues name consumers | grep 'some-queue' | awk '{ print $2 }'
UserParameter=batch.queue.memory,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_queues name memory | grep 'some-queue' | awk '{ print $2 }'
#
# some-exchange statistics.
#
UserParameter=batch.exchange.durable,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_exchanges name durable | grep 'some-exchange' | awk '{ print $2 }'
UserParameter=batch.exchange.type,sudo /usr/sbin/rabbitmqctl -n prod_rabbitmq-rabbit list_exchanges name type | grep 'some-exchange' | awk '{ print $2 }'
After making the changes, bounce (restart) the zabbix-agent service on the rabbitmq server box.
Sudo Permissions
The parameters won't work until the zabbix group is granted non-password sudo access. I chose to add a new file at /etc/sudoers.d/rabbitmqserverstats.
I added the following line to the end of /etc/sudoers:
#includedir /etc/sudoers.d
/etc/sudoers.d/rabbitmqserverstats contains:
# RabbitMQ Server Stats Sudoers # # This grants the zabbix group non-password sudo access to rabbitmqctl. # %zabbix ALL=(ALL) NOPASSWD: /usr/sbin/rabbitmqctl
And with that, Zabbix should be able to monitor the some-queue and some-exchange statistics.
Update: Posted to RabbitMQ Server Stats template on ZabbixTemplates.com. Now gone; links go to web archive.