Skip to content

RabbitMQ — alert on queue depth growth

Consumer can not keep up; queue grows; disk eventually fills. Need an alert on messages-ready count.

Recipe

bash
#!/usr/bin/env bash
# /opt/rmq-depth.sh — expose queue depth as plain text
QUEUE="${1:-payments}"
VHOST="${2:-%2F}"  # url-encoded /
RMQ_USER="${RMQ_USER:-guest}"
RMQ_PASS="${RMQ_PASS:-guest}"
THRESHOLD="${DEPTH_THRESHOLD:-5000}"

DEPTH=$(curl -s -u "$RMQ_USER:$RMQ_PASS" \
        "http://localhost:15672/api/queues/$VHOST/$QUEUE" \
        | python3 -c 'import json,sys; print(json.load(sys.stdin).get("messages_ready",-1))')

[ "$DEPTH" -lt 0 ] && { echo "no-data"; exit 1; }
[ "$DEPTH" -ge "$THRESHOLD" ] && echo "deep $DEPTH" || echo "ok $DEPTH"

Same thing in Enterno.io

Endpoint + Enterno HTTP monitor with keyword "ok" gives an instant Telegram alert when the queue blows past threshold. Pro+ stores response-time which often correlates with a deep queue.

Set up HTTP monitor → ← All recipes

Related recipes