Last active
April 9, 2021 15:36
-
-
Save sr2ds/68c4148cc1f3c951fd833c1e06ceda4f to your computer and use it in GitHub Desktop.
Check Queues Health Redis Docker Containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 protected]" | |
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