Created
June 3, 2016 19:48
-
-
Save jbuck/0cee36c9693c983b7df03bc78d8ba37b to your computer and use it in GitHub Desktop.
Read RQ metrics and put into CloudWatch
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 | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
# set -o xtrace | |
COUNT=60 | |
REDIS_HOST=$2 | |
if [ "$1" == "jobs-in-queue" ]; then | |
DATA=`redis-cli --raw -r $COUNT -i 1 -h $REDIS_HOST llen rq:queue:default | sort -n` | |
METRICNAME="JobsInQueue" | |
elif [ "$1" == "online-workers" ]; then | |
DATA=`redis-cli --raw -r $COUNT -i 1 -h $REDIS_HOST scard rq:workers | sort -n` | |
METRICNAME="OnlineWorkers" | |
elif [ "$1" == "busy-workers" ]; then | |
WORKERS=`redis-cli --raw -h $REDIS_HOST smembers rq:workers` | |
WORKER_COUNT=`echo $WORKERS | wc -w` | |
DATA=`redis-cli --raw -r $COUNT -i 1 -h $REDIS_HOST EVAL "local count = 0 for i,v in ipairs(KEYS) do if redis.call('hget', v, 'state') == 'busy' then count = count + 1 end end return count" $WORKER_COUNT $WORKERS | sort -n` | |
METRICNAME="BusyWorkers" | |
elif [ "$1" == "idle-workers" ]; then | |
WORKERS=`redis-cli --raw -h $REDIS_HOST smembers rq:workers` | |
WORKER_COUNT=`echo $WORKERS | wc -w` | |
DATA=`redis-cli --raw -r $COUNT -i 1 -h $REDIS_HOST EVAL "local count = 0 for i,v in ipairs(KEYS) do if redis.call('hget', v, 'state') == 'idle' then count = count + 1 end end return count" $WORKER_COUNT $WORKERS | sort -n` | |
METRICNAME="IdleWorkers" | |
else | |
echo "Must specify a command" | |
exit 1 | |
fi | |
DATE=`date -u "+%Y-%m-%dT%H:%M:%SZ"` | |
SUM=`echo "$DATA" | awk '{s+=$1} END {print s}'` | |
MIN=`echo "$DATA" | head -n 1` | |
MAX=`echo "$DATA" | tail -n 1` | |
echo "aws cloudwatch put-metric-data --namespace 'EmbedlyProxy' --metric-name $METRICNAME --timestamp $DATE --unit Count --statistic-value Sum=$SUM,Minimum=$MIN,Maximum=$MAX,SampleCount=$COUNT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic!