SpringBoot RabbitMQ Actuator (Queue Metrics & Health-Checks)
<dependency>
<groupId>com.itelg.spring</groupId>
<artifactId>spring-rabbitmq-actuator</artifactId>
<version>0.6.0-RC2</version>
</dependency>
Precondition (Example)
You have to add the declaring RabbitAdmin to each queue. The specific RabbitAdmin is required to fetch the queue-information.
@Bean
public Queue exampleQueue()
{
Queue queue = new Queue("com.itelg.spring.rabbitmq.test");
queue.setAdminsThatShouldDeclare(rabbitAdmin());
return queue;
}
@Bean
public HealthIndicator rabbitQueueCheckHealthIndicator()
{
RabbitQueueCheckHealthIndicator healthIndicator = new RabbitQueueCheckHealthIndicator();
healthIndicator.addQueueCheck(exampleQueue1, 10000, 1);
healthIndicator.addQueueCheck(exampleQueue2, 50000, 3);
return healthIndicator;
}
Response (/actuator/health)
{
"status" : "DOWN",
"rabbitQueueCheck" :
{
"status" : "DOWN",
"com.examle.exampleQueue1" :
{
"status" : "UP",
"currentMessageCount" : 214,
"maxMessageCount" : 10000,
"currentConsumerCount" : 5,
"minConsumerCount" : 1
},
"com.example.exampleQueue2" :
{
"status" : "DOWN",
"currentMessageCount" : 67377,
"maxMessageCount" : 50000,
"currentConsumerCount" : 0,
"minConsumerCount" : 3
}
}
}
@EnableRabbitMetrics
@Configuration
public class RabbitMetricsConfiguration
{
}
Response (/actuator/metrics)
{
"names" :
[
"jvm.memory.used",
"process.cpu.usage",
"...",
"rabbitmq.queue.messages.current",
"rabbitmq.queue.consumers.current",
"rabbitmq.queue.messages.max",
"rabbitmq.queue.consumers.min",
"..."
]
}
Detailed:
{
"name": "rabbitmq.queue.messages.current",
"description": null,
"baseUnit": null,
"measurements": [
{
"statistic": "VALUE",
"value": 215
}
],
"availableTags" : [ {
"tag" : "queue",
"values" : [ "dlq-example-simple-queue-dlq", "dlq-example-simple-queue" ]
} ]
}
Prometheus-Example:
# HELP rabbitmq_queue_messages_current
# TYPE rabbitmq_queue_messages_current gauge
rabbitmq_queue_messages_current{queue="dlq-example-simple-queue",} 0.0
rabbitmq_queue_messages_current{queue="dlq-example-simple-queue-dlq",} 371.0
# HELP rabbitmq_queue_consumers_current
# TYPE rabbitmq_queue_consumers_current gauge
rabbitmq_queue_consumers_current{queue="dlq-example-simple-queue",} 1.0
rabbitmq_queue_consumers_current{queue="dlq-example-simple-queue-dlq",} 0.0