Monitoring and Observability
1. Using Management API
| Endpoint | Method | Description | Notes |
|---|---|---|---|
| /api/queues/{vhost}/{queue} | GET | Retrieve queue details | Returns queue configuration and stats |
| /api/exchanges/{vhost}/{exchange} | GET | Retrieve exchange details | Includes exchange type and bindings |
| /api/nodes | GET | List all nodes in cluster | Shows node status and memory usage |
| /api/connections | GET | List active connections | Includes client IP and connection details |
Note: Authentication is required. Default credentials are
guest/guest.Example: Getting Node Statistics
const axios = require('axios');
const getNodesStats = async () => {
const response = await axios.get('http://localhost:15672/api/nodes', {
auth: {
username: 'guest',
password: 'guest'
}
});
return response.data.map(node => ({
name: node.name,
status: node.status,
memory: node.mem_used / (1024 * 1024) + ' MB'
}));
};
Common Management API Use Cases
- Monitor queue depths and message rates
- Track connection and channel usage
- Identify bottlenecks in message flow
- View exchange and queue configurations
- Debug routing issues with bindings
2. Monitoring Queue Metrics
| Metric | Description | Unit | Notes |
|---|---|---|---|
| queue.messages | Number of messages in the queue | count | Includes unacknowledged messages |
| queue.messages.ready | Number of messages ready to be delivered | count | Excludes unacknowledged messages |
| queue.messages.unacked | Number of unacknowledged messages | count | Messages that have been delivered but not yet acknowledged |
| queue.message.bytes | Total size of messages in the queue (in bytes) | bytes | Includes all message content and metadata |
| queue.message.bytes.ready | Size of ready messages in the queue (in bytes) | bytes | Excludes unacknowledged messages |
| queue.message.bytes.unacked | Size of unacknowledged messages in the queue (in bytes) | bytes | Messages that have been delivered but not yet acknowledged |
| queue.consumer.count | Number of active consumers on the queue | count | Active consumers that are currently receiving messages |
| queue.messages.ack.rate | Acknowledgement rate (messages per second) | messages/sec | Rate at which messages are acknowledged by consumers |
| queue.messages.deliver.rate | Delivery rate (messages per second) | messages/sec | Rate at which messages are delivered to consumers |
| queue.messages.publish.rate | Publish rate (messages per second) | messages/sec | Rate at which messages are published to the queue |
Example: Fetching Queue Metrics via RabbitMQ Management API
curl -u guest:guest http://localhost:15672/api/queues/%2f/my-queue
Example: Sample Response from Management API
{
"messages": 100,
"messages_ready": 50,
"messages_unacknowledged": 50,
"message_bytes": 102400,
"message_bytes_ready": 51200,
"message_bytes_unacknowledged": 51200,
"consumers": 2,
"ack_rate": 10.5,
"deliver_rate": 15.2,
"publish_rate": 20.0
}
Note: Metrics are exposed via the RabbitMQ Management HTTP API and can be used for monitoring tools like Prometheus or Grafana.
3. Monitoring Connection Metrics
| Metric | Description | Unit | Notes |
|---|---|---|---|
| connections | Total number of active connections | count | Includes all connections to the broker |
| connection_close_ok | Number of successful connection closures | count | Tracks clean shutdowns |
| connection_close_error | Number of failed connection closures | count | Tracks errors during closure |
| connection_open | Number of new connection openings | count | Tracks successful connection establishment |
Example: Fetching Connection Metrics via RabbitMQ Management API
curl -u guest:guest http://localhost:15672/api/connections
Example: Parsing Connection Metrics in JavaScript
const axios = require('axios');
async function fetchConnectionMetrics() {
const response = await axios.get('http://localhost:15672/api/connections', {
auth: { username: 'guest', password: 'guest' }
});
const connections = response.data;
console.log(`Active connections: ${connections.length}`);
console.log('Connection details:', connections.map(conn => ({
name: conn.name,
user: conn.user,
state: conn.state
})));
}
fetchConnectionMetrics();
4. Monitoring Node Metrics
| Metric | Description | Unit | Notes |
|---|---|---|---|
| process.cpu.percent | CPU usage percentage of the RabbitMQ process | % | Value between 0 and 100 |
| process.memory.rss | Resident Set Size (physical memory used by the process) | bytes | Includes all memory allocated by the OS |
| process.memory.vsize | Virtual memory size of the process | bytes | Total virtual memory used by the process |
| disk.space.available | Available disk space on the node | bytes | Used for storing message data and logs |
| disk.space.total | Total disk space on the node | bytes | Sum of all available disks |
| messages.incoming | Number of messages received per second | messages/sec | Includes all incoming messages to the broker |
| messages.delivered | Number of messages delivered per second | messages/sec | Includes all messages delivered to consumers |
| messages.acknowledged | Number of messages acknowledged per second | messages/sec | Messages successfully processed and acknowledged by consumers |
| messages.unacked | Number of unacknowledged messages in queues | messages | Messages that have been delivered but not yet acknowledged |
| connections.count | Current number of active connections | connections | Active client connections to the broker |
| channels.count | Current number of active channels | channels | Active channels within connections |
| queues.count | Current number of queues in the node | queues | Total queues created on this node |
| exchanges.count | Current number of exchanges in the node | exchanges | Total exchanges created on this node |
| consumers.count | Current number of consumers connected to queues | consumers | Total consumers subscribed to queues |
Example: Fetching Node Metrics via Management API
curl -u guest:guest http://localhost:15672/api/nodes/rabbit@localhost
Example: Monitoring CPU Usage with Prometheus
prometheus:
scrape_configs:
- job_name: rabbitmq
static_configs:
- targets: ['localhost:15692']
Note: RabbitMQ exposes metrics via the Management Plugin and Prometheus Exporter. Ensure that the
rabbitmq_management and rabbitmq_prometheus plugins are enabled.
5. Monitoring Channel Metrics
| Metric | Description | Unit | Notes |
|---|---|---|---|
| channel.messages.published | Number of messages published to the channel | count | Incremented for each message published |
| channel.messages.acknowledged | Number of messages acknowledged by consumers | count | Tracks successful consumer acknowledgments |
| channel.messages.nacknowledged | Number of messages negatively acknowledged by consumers | count | Tracks failed consumer acknowledgments |
| channel.messages.redelivered | Number of messages redelivered to consumers | count | Indicates message reprocessing due to failure |
| channel.messages.unroutable | Number of messages that could not be routed to any queue | count | Indicates routing configuration issues |
| channel.consumer.count | Current number of active consumers on the channel | count | Helps identify consumer load |
Example: Publishing a message and monitoring metrics
const amqp = require('amqplib');
async function publishAndMonitor() {
const connection = await amqp.connect('amqp://localhost');
const channel = await connection.createChannel();
// Publish a message
const msg = 'Hello, RabbitMQ!';
channel.publish('', 'my-queue', Buffer.from(msg));
// Monitor metrics using RabbitMQ Management API
const metrics = await fetch('http://localhost:15672/api/channels');
console.log(await metrics.json());
await channel.close();
await connection.close();
}
publishAndMonitor();
Note: Channel metrics are collected per channel and can be accessed via the RabbitMQ Management HTTP API or through Prometheus integration.
6. Collecting Prometheus Metrics
Example: Enable Prometheus in RabbitMQ
# Enable Prometheus plugin
rabbitmq-plugins enable rabbitmq_prometheus
# Restart RabbitMQ service
systemctl restart rabbitmq-server
| Configuration Option | Default Value | Description |
|---|---|---|
| prometheus.tcp.port | 15691 |
TCP port for Prometheus metrics endpoint |
| prometheus.tcp.ip_address | 0.0.0.0 |
IP address to bind the Prometheus listener |
| prometheus.http.api_enabled | true |
Enable HTTP API for metrics |
Note: Prometheus metrics are exposed via the
/metrics endpoint on port 15691 by default.
Example: Prometheus scrape configuration
scrape_configs:
- job_name: 'rabbitmq'
static_configs:
- targets: ['localhost:15691']
Key Metrics Exposed by RabbitMQ
rabbitmq_queue_messages- Number of messages in a queuerabbitmq_connection_count- Number of active connectionsrabbitmq_channel_count- Number of active channelsrabbitmq_message_deliver_rate- Rate of message deliveries per second
7. Setting Alarms
| Alarm Name | Description | Trigger Condition | Severity |
|---|---|---|---|
| queue.length | Triggers when the number of messages in a queue exceeds a threshold | Messages in queue > 1000 | Warning |
| queue.consumer.count | Triggers when the number of consumers on a queue drops below a threshold | Consumers < 1 | Critical |
| node.memory.usage | Triggers when node memory usage exceeds a threshold | Memory usage > 85% | Critical |
| node.disk.usage | Triggers when disk usage exceeds a threshold | Disk usage > 90% | Warning |
Example: Configure queue length alarm via RabbitMQ Management UI
curl -u guest:guest -X POST "http://localhost:15672/api/alarms" \
-H "Content-Type: application/json" \
-d '{
"name": "queue.length",
"description": "Queue length exceeds 1000 messages",
"severity": "warning",
"condition": {
"type": "queue.length",
"threshold": 1000
}
}'
Note: Alarms can be configured via the RabbitMQ Management HTTP API or through the UI. Ensure that monitoring tools are set up to receive alarm notifications.
8. Using Health Checks
Example: RabbitMQ Health Check Endpoint
curl -X GET http://localhost:15672/api/healthchecks/node/rabbit@localhost
| Endpoint | Method | Description | Notes |
|---|---|---|---|
| /api/healthchecks/node/<node> | GET | Checks the health of a specific RabbitMQ node | Returns status code 200 if healthy, 503 if not |
| /api/healthchecks/cluster | GET | Checks the health of the entire cluster | Validates all nodes and queues in the cluster |
Note: Health checks are typically used by orchestration tools like Kubernetes to determine if RabbitMQ is ready to receive traffic.
Example: Kubernetes Liveness Probe Configuration
livenessProbe:
httpGet:
path: /api/healthchecks/node/rabbit@localhost
port: 15672
initialDelaySeconds: 30
periodSeconds: 10
9. Enabling Event Logging
| Configuration Option | Values | Description |
|---|---|---|
| log.console | true |
Enable console logging of events |
| log.file | /var/log/rabbitmq/rabbit.log |
Path to the log file |
| log.level | info |
Log level: debug, info, warning, error |
Example: Set Log File Path
echo 'log.file = /var/log/rabbitmq/rabbit.log' >> /etc/rabbitmq/rabbitmq.conf
Note: Changes to the configuration file require a RabbitMQ service restart to take effect.
10. Using Tracing
Example: Setting up OpenTelemetry for RabbitMQ
# otel-config.yaml
receivers:
jaeger:
protocols:
thrift_http:
endpoint: "0.0.0.0:14268"
otlp:
protocols:
http:
endpoint: "0.0.0.0:4318"
processors:
batch:
timeout: 1s
exporters:
jaeger:
endpoint: "http://jaeger-collector:14250"
tls:
insecure: true
service:
pipelines:
traces:
receivers: [jaeger, otlp]
processors: [batch]
exporters: [jaeger]
| Component | Description | Notes |
|---|---|---|
| Jaeger Receiver | Receives trace data from RabbitMQ clients | Supports Jaeger Thrift format |
| OTLP Exporter | Exports traces to OpenTelemetry Collector | Supports gRPC and HTTP protocols |
Note: RabbitMQ supports OpenTelemetry tracing via the
rabbitmq-observability plugin.
Warning: Tracing can impact performance; enable only in production environments with proper sampling.
Tracing Configuration Options
- NEW
rabbitmq_tracing.enabled: Enable/disable tracing (default: false) - NEW
rabbitmq_tracing.exporter: Choose exporter (jaeger, otlp) - NEW
rabbitmq_tracing.sample_rate: Trace sampling rate (default: 0.1)
11. Integrating with Grafana
Example: Setting up RabbitMQ Grafana Dashboard
{
"dashboard": {
"title": "RabbitMQ Overview",
"panels": [
{
"title": "Queue Length",
"type": "graph",
"targets": [
{
"expr": "rabbitmq_queue_messages{queue='my-queue'}"
}
]
}
]
}
}
| Panel Type | Metric Expression | Description |
|---|---|---|
| Queue Length | rabbitmq_queue_messages{queue='my-queue'} |
Number of messages in a queue |
| Message Rate | rabbitmq_messages_published_total |
Total messages published per second |
| Connection Count | rabbitmq_connections |
Active connections to the broker |
Note: Ensure the
rabbitmq_exporter is running and exposing metrics at /metrics.
Warning: Grafana dashboards may require Prometheus as a data source for metric collection.
12. Setting Up Alerting
Example: Basic RabbitMQ Alerting Configuration
# rabbitmq.conf
management.enabled = true
management.listener.port = 15672
management.listener.ip = 0.0.0.0
# Enable alerting
rabbitmq_management.alerts.enabled = true
rabbitmq_management.alerts.thresholds.memory.usage = 80
rabbitmq_management.alerts.thresholds.disk.usage = 90
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| rabbitmq_management.alerts.enabled | Enable or disable alerting | false |
Set to true to enable |
| rabbitmq_management.alerts.thresholds.memory.usage | Memory usage percentage threshold to trigger alert | 80 |
Percentage of total memory |
| rabbitmq_management.alerts.thresholds.disk.usage | Disk usage percentage threshold to trigger alert | 90 |
Percentage of disk space |
| rabbitmq_management.alerts.thresholds.queue.length | Queue length threshold to trigger alert | 10000 |
Number of messages in queue |
Note: Alerts can be configured via
rabbitmq.conf or through the management API.