# RabbitMQ + Management + Prometheus

> Message broker with management UI and monitoring.

- Category: Message Queues & Brokers
- Difficulty: intermediate
- Components: rabbitmq, prometheus, grafana
- Tags: rabbitmq, message-queue, amqp, broker, messaging
- Source: https://docker.recipes/messaging/rabbitmq-complete

## Overview

RabbitMQ is a robust, enterprise-grade message broker that implements the Advanced Message Queuing Protocol (AMQP) and serves as the backbone for distributed system communication. Originally developed by Rabbit Technologies in 2007 and later acquired by VMware, RabbitMQ has become the most widely deployed open-source message broker, handling millions of messages per second in production environments worldwide. Its strength lies in reliable message delivery, flexible routing capabilities, and support for multiple messaging protocols including AMQP, MQTT, and STOMP.

This monitoring stack combines RabbitMQ's management interface with Prometheus metrics collection and Grafana visualization to create a comprehensive observability solution. Prometheus scrapes metrics from RabbitMQ's built-in prometheus plugin (exposed on port 15692), while Grafana transforms this time-series data into actionable dashboards. The management UI provides real-time queue inspection and administrative controls, while Prometheus captures historical performance data for trend analysis and alerting.

Development teams building microservices architectures, platform engineers managing message-driven systems, and operations teams requiring deep visibility into message broker performance will find this stack invaluable. The combination provides both immediate troubleshooting capabilities through the management UI and long-term capacity planning insights through Grafana dashboards, making it essential for production RabbitMQ deployments.

## Features

- AMQP 0-9-1 protocol implementation with message acknowledgments and persistent queues
- Built-in Prometheus metrics exporter providing queue depth, message rates, and connection statistics
- Web-based management interface for queue inspection, exchange configuration, and user management
- PromQL query language support for complex metric aggregation and alerting rules
- Multi-protocol support including MQTT for IoT devices and STOMP for web applications
- Grafana dashboard templating for monitoring multiple RabbitMQ clusters from single interface
- Dead letter exchange handling for failed message processing and debugging
- Time-series metric storage with configurable retention policies in Prometheus

## Use cases

- Microservices event-driven architectures requiring reliable inter-service communication monitoring
- IoT platforms processing MQTT messages with need for throughput and latency visibility
- E-commerce order processing systems monitoring queue backlogs and processing rates
- Task queue systems like Celery requiring worker performance and job completion tracking
- Financial services message processing with strict delivery guarantees and audit trails
- DevOps teams implementing infrastructure monitoring for message broker capacity planning
- Development environments requiring message flow debugging and performance optimization

## Prerequisites

- Docker Engine 20.10+ and Docker Compose 2.0+ with at least 2GB available RAM
- Basic understanding of message queuing concepts and AMQP protocol fundamentals
- Familiarity with PromQL query language for creating custom Grafana dashboard panels
- Network ports 3000, 5672, 9090, 15672, and 15692 available on the host system
- Knowledge of RabbitMQ exchange types (direct, topic, fanout) for effective monitoring setup

## docker-compose.yml

```yaml
services:
  rabbitmq:
    image: rabbitmq:3-management
    environment:
      - RABBITMQ_DEFAULT_USER=${RABBITMQ_USER}
      - RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASSWORD}
    volumes:
      - rabbitmq-data:/var/lib/rabbitmq
      - ./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
    ports:
      - "5672:5672"
      - "15672:15672"
      - "15692:15692"
    networks:
      - rabbitmq-network
    restart: unless-stopped

  prometheus:
    image: prom/prometheus:latest
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus
    ports:
      - "9090:9090"
    networks:
      - rabbitmq-network
    restart: unless-stopped

  grafana:
    image: grafana/grafana:latest
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}
    volumes:
      - grafana-data:/var/lib/grafana
    ports:
      - "3000:3000"
    depends_on:
      - prometheus
    networks:
      - rabbitmq-network
    restart: unless-stopped

volumes:
  rabbitmq-data:
  prometheus-data:
  grafana-data:

networks:
  rabbitmq-network:
    driver: bridge
```

## .env

```bash
# RabbitMQ
RABBITMQ_USER=admin
RABBITMQ_PASSWORD=secure_rabbitmq_password
GRAFANA_PASSWORD=secure_grafana_password

# Enable prometheus plugin in rabbitmq.conf
```

## Usage notes

- AMQP at port 5672
- Management at http://localhost:15672
- Prometheus metrics at port 15692
- Grafana at http://localhost:3000
- Enable plugins: rabbitmq-plugins enable rabbitmq_prometheus

## Troubleshooting

- Connection refused on port 15692: Enable Prometheus plugin with 'rabbitmq-plugins enable rabbitmq_prometheus' command in container
- Grafana shows no data from Prometheus: Verify prometheus.yml contains correct RabbitMQ scrape target 'rabbitmq:15692'
- RabbitMQ management UI login fails: Check RABBITMQ_DEFAULT_USER and RABBITMQ_DEFAULT_PASS environment variables are set
- High memory usage in RabbitMQ container: Configure message TTL and queue length limits in rabbitmq.conf file
- Prometheus target shows as down: Ensure rabbitmq_prometheus plugin is enabled and port 15692 is accessible between containers
- Missing metrics in Grafana dashboards: Import official RabbitMQ dashboard ID 10991 from Grafana dashboard library

