Metrics and observability
Metrics and observability
Structured logs explain a particular failure; numeric metrics explain system health. Install the optional dependency:
pip install 'Flask-RMQ[metrics]'Instrument the boundaries of publication and handler execution. Recommended Prometheus series:
| Metric | Type | Labels |
|---|---|---|
rabbitmq_publish_total | counter | queue, exchange, result |
rabbitmq_publish_duration_seconds | histogram | queue, exchange |
rabbitmq_publish_reconnect_total | counter | queue, exchange |
rabbitmq_consume_total | counter | queue, result |
rabbitmq_consume_duration_seconds | histogram | queue |
rabbitmq_consume_reconnect_total | counter | queue |
rabbitmq_consume_in_flight | gauge | queue |
Expose Flask process metrics with prometheus_client.make_wsgi_app() through a dispatcher or a small Blueprint. A consumer-only deployment can call prometheus_client.start_http_server(9100) before starting consumer threads.
Multi-process warning
Gunicorn workers do not share ordinary in-memory counters. Configure PROMETHEUS_MULTIPROC_DIR, create a CollectorRegistry, and attach multiprocess.MultiProcessCollector when exposing metrics from a multi-worker API. Consumer containers normally run one process and do not need multiprocess mode.
Broker metrics
Application metrics are not enough. Enable RabbitMQ's official Prometheus plugin and alert on ready messages, unacknowledged messages, disk/memory alarms, connection churn, and consumer count.
Useful starting alerts:
- any sustained publish error rate;
- reconnect storms;
- queue depth growing while consume rate is zero;
- handler error rate above the service threshold;
- no registered consumers for a queue expected to be active.
Keep queue and exchange labels bounded. Never label by message ID, routing payload, user, or error text.