Skip to content

Instantly share code, notes, and snippets.

@sr2ds
Last active April 9, 2021 15:36
Show Gist options
  • Save sr2ds/68c4148cc1f3c951fd833c1e06ceda4f to your computer and use it in GitHub Desktop.
Save sr2ds/68c4148cc1f3c951fd833c1e06ceda4f to your computer and use it in GitHub Desktop.
Check Queues Health Redis Docker Containers
#!/bin/bash
## Check Queues Health Redis Docker Containers
# if your have many redis containers with queue processing, this script can help you
# when any application worker stop or have delayed, this script can send mail for you with this information
sendTo="email@email.com"
lengthToWarning="10"
docker ps | grep redis | awk '{print $1}' | while read container; do
queues=$(echo 'keys *' | xargs docker exec $container redis-cli | grep queue | grep -v reserved)
queuesCount=$(echo 'keys *' | xargs docker exec $container redis-cli | grep queue | wc -l)
queuesArray=$(echo $queues | tr " ", "\n")
for queue in $queuesArray; do
queueLength=$(echo llen $queue | xargs docker exec $container redis-cli)
if [ "$queueLength" -gt "$lengthToWarning" ]; then
containerName=$(docker ps --format="{{.ID}} {{.Names}}" | grep $container | awk '{print $2}')
echo "Queues Redis: $containerName: $queue have $queueLength itens to processed, its normal?." >> tmpQueueChecker
fi
done
done
TOTAL=$(cat tmpQueueChecker | uniq | wc -l)
if [[ "$TOTAL" -gt "0" ]]; then
cat tmpQueueChecker | mutt -s "Warning - Many Queues Waiting Process" $sendTo
rm tmpQueueChecker
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment