Skip to content

Instantly share code, notes, and snippets.

@Jinkxed
Last active February 15, 2016 16:39
Show Gist options
  • Save Jinkxed/d765b0d34a8d1159c81f to your computer and use it in GitHub Desktop.
Save Jinkxed/d765b0d34a8d1159c81f to your computer and use it in GitHub Desktop.
#!/bin/bash
############################################################
# run: cloudwatch_push -e staging -q rabbit_queue_name
############################################################
while getopts e:q:c:h: option
do
case "${option}"
in
e) environment=${OPTARG};;
q) queue=${OPTARG};;
esac
done
source /etc/bashrc
date=`date`
home="/opt/scripts/"
cd $home
case $environment in
production)
user='someuser'
pass=somepass'
url='sub.example.com'
vhost='root_vhost (eg: someuser)'
;;
staging)
user=
pass=
url=
vhost=
;;
qa)
user=
pass=
url=
vhost=
;;
esac
function get_queue() {
response=`/usr/bin/curl -s -u ${user}:${pass} https://$url/api/queues/$vhost/$queue`
count=`echo $response | jq -r '.messages'`
echo $count
}
function push_to_cloudwatch() {
count=$(get_queue)
echo "${queue}: ${count}"
aws cloudwatch put-metric-data --metric-name "QueueLength" --namespace ${queue} --value ${count} --unit Count
}
push_to_cloudwatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment