Skip to content

Redis Streams — alert when XPENDING grows

A Redis Streams consumer lags — it reads messages but never XACKs them (the worker hangs between read and ack). XLEN does not grow, XPENDING does.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/redis-streams
# */2 * * * * root /opt/redis-streams.sh

HOST=${REDIS_HOST:-127.0.0.1}
STREAM=${STREAM}
GROUP=${CONSUMER_GROUP}
THRESH=${THRESH:-100}                 # alert above pending count

PENDING=$(redis-cli -h "$HOST" XPENDING "$STREAM" "$GROUP" | head -1)

if [ "${PENDING:-0}" -gt "$THRESH" ]; then
  curl -fsS "$HEARTBEAT_URL" --data "pending=$PENDING,stream=$STREAM,group=$GROUP"
  exit 2
fi
echo "OK (pending=$PENDING)"

Same thing in Enterno.io

Wire to an Enterno heartbeat — a couple of minutes without ack from the consumer is already a trend, you spot it before pipeline-wide degradation.

Set up HTTP monitor → ← All recipes

Related recipes