Created
January 13, 2015 19:24
-
-
Save rjz/0f68a6e6ffbae4c28497 to your computer and use it in GitHub Desktop.
rabbitmq-queue-monitor
This file contains hidden or 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 | |
| # | |
| # Use RabbitMQ admin plugin to monitor backed up queues. If `THRESHOLD` is | |
| # exceeded, an error list will be served at 127.0.0.1:1334/overage.txt. If | |
| # all queues are below the threshold, requests for the overage file should | |
| # expect a 404. | |
| # API host, user, and password | |
| HOST=127.0.0.1:15672 | |
| USER=admin | |
| PASS=password | |
| # Queues to monitor | |
| QUEUES='queue1 queue2 etc' | |
| # Number of messages in queue before a notice | |
| THRESHOLD=10000 | |
| # polling interval (seconds) | |
| INTERVAL=30 | |
| # Port to serve watcher on | |
| PORT=1334 | |
| # Directory to serve watcher files from, and the name of the | |
| # overage file | |
| SERVERDIR=.monitor | |
| OVERAGEFILE="$SERVERDIR/overage.txt" | |
| SCRIPTDIR=`${PWD##*/}` | |
| if [ -f pid ]; then | |
| kill `cat pid` | |
| rm pid | |
| fi | |
| if [ ! -d "$SERVERDIR" ]; then mkdir -p "$SERVERDIR" fi | |
| rm -rf "$SERVERDIR/*" | |
| cd "$SERVERDIR" | |
| python -mSimpleHTTPServer $PORT 2>&1 > /dev/null & | |
| pid=$! | |
| cd "$SCRIPTDIR" | |
| while true; do | |
| failing=0 | |
| for q in $QUEUES; do | |
| counts=$(curl -s $HOST/api/queues/$q --user $USER:$PASS \ | |
| | python -mjson.tool \ | |
| | grep '"messages"' \ | |
| | sed 's/\s*"messages": \([0-9]*\).*/\1/' \ | |
| | tr '\n' ' ') | |
| for c in $counts; do | |
| if [ $c -gt $THRESHOLD ]; then | |
| failing=1 | |
| echo "$q @ $c (MAX: $THRESHOLD)" >> queues.txt | |
| fi | |
| done | |
| done | |
| if [ $failing -eq 0 ] && [ -f "$OVERAGEFILE" ]; then rm "$OVERAGEFILE"; fi | |
| sleep $INTERVAL | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment