Skip to main content

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_load1{instance=~”rabbit-cluster-node-.*”}
  • 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:
node_memory_MemUsed{instance=~”rabbit-cluster-node-.*”}
  • 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"})

Comments

Popular posts from this blog

RabbitMQ Queues- High Availability and Migration

RabbitMQ stores contents of a queue on a single node by default. We can optionally mirror these contents across different nodes. Each mirrored queue has one master and one or more mirrors. Any operation that takes place on the queue like adding a message, consuming a message etc. happens on the master node first. Since all the messages are replicated across all mirrors and all the operations are also propagated to them, adding mirrors does not reduce the load on the queue. However, it provides us with high availability. In case, the node on which master for your mirror is located goes down, one of the mirrors can take over without impacting the availability of the queue. We can setup various different mirroring policies to suit our availability requirements. RabbitMQ provides 3 policies out of the box: Exactly: Using this you can specify exact number of replicas(master + mirrors) for the queue in the cluster. All: Queue will be replicated across all nodes on cluster. Use this ...

Monitoring Spring Boot API response times with Prometheus

Prometheus is a very useful tool for monitoring web applications. In this blog post, we will see how to use it to monitor Spring Boot API response times. You have to include following dependencies in your build.gradle file: compile group: 'io.prometheus', name: 'simpleclient_hotspot', version: '0.0.26' compile group: 'io.prometheus', name: 'simpleclient_servlet', version: '0.0.26' compile group: 'io.prometheus', name: 'simpleclient', version: '0.0.26' Now you will have to expose a Rest Endpoint, so that Prometheus can collect the metrics by scraping it at regular intervals. To do that, you would have to include these Java configuration classes: @Configuration @ConditionalOnClass(CollectorRegistry.class) public class Config { private static final CollectorRegistry metricRegistry = CollectorRegistry. defaultRegistry ; @Bean ServletRegistrationBean registerPrometheusExporterServlet() { retu...