Monitoring RabbitMQ with Prometheus and Grafana

Monitoring is one of the most important parts of any production setup. Good monitoring is critical to detect any issues before they impact your systems and eventually the users.

Prometheus is an open source time series data store. It works on a pull based model where you have to expose an endpoint from where Prometheus can pull. We can use prometheus_rabbitmq_exporter plugin to expose /api/metrics endpoint in the context on RabbitMQ management API. For installation and setup instructions, we can follow this article on RabbitMQ website. Once the setup is done, read this article to learn more about which metrics you should monitor and how to do that using Prometheus.

First we will look at system metrics:

  • Node Load Average: This metric indicates the Average load on CPU. It should be less than the number of cores on the node CPU. You should setup alerts if this goes higher than number of CPU cores available. Query to setup the graph for this is:
  • Node Used Memory: This metric indicates the average amount of memory used on each node. you should setup alerts if this goes higher than the watermark. Watermark is generally (0.4 * Node Memory). Query to setup this graph is:
  • Queue Depth: This metric how many messages are currently waiting to be consumed in any queue. If this number increases too much than it can cause performance issues due to increased memory usage. Queries to setup graph for this are:
sum(rabbitmq_queue_messages{queue=~”$queue”, policy=~”$policy”, durable=~”$durable”, vhost=~”$vhost”})
sum(rabbitmq_queue_messages_ram{queue=~"$queue", policy=~"$policy", durable=~"$durable", vhost=~"$vhost"})
um(rabbitmq_queue_messages_persistent{queue=~"$queue", policy=~"$policy", durable=~"$durable", vhost=~"$vhost"})

These would also give the number of messages being stored in memory and on the disk for any queue.

  • Number of consumers for a Queue: Setup an alert if number of consumers any queue drops lower than a pre defined threshold. Query to setup graph for this metric is:
sum(rabbitmq_queue_consumers{queue=~"$queue", policy=~"$policy", durable=~"$durable", vhost=~"$vhost"})
  • Queue Consumer Utilization: Consumer Utilization is the proportion of time that a queue’s consumers could take new messages. This is a number number 0 to 100%. If a queue has consumer utilization as 100%, then its able to push out messages as fast as it can and doesn’t need to wait on consumers. Setup alerts on this if it drops lower than a pre defined threshold for any queue. Query to setup graph for this metric is:
max(rabbitmq_queue_consumer_utilisation{queue=~"$queue", policy=~"$policy", durable=~"$durable", vhost=~"$vhost"})
  • Queue Memory: Queue Memory indicates the amount of memory consumed by the queue. Set to alert on this metric if it breaches a predefined threshold for any queue. Query to setup graph for this metric is:
max(rabbitmq_queue_memory{queue=~"$queue", policy=~"$policy", durable=~"$durable", vhost=~"$vhost"})