Skip to content

Instantly share code, notes, and snippets.

@epleterte
Last active December 23, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epleterte/6641165 to your computer and use it in GitHub Desktop.
Save epleterte/6641165 to your computer and use it in GitHub Desktop.
nginx upstream status in your terminal...
#!/bin/bash -ue
domain="customer.com"
environment=$( facter -p customer_env )
proto="http"
lb_host="web1.${environment}.${domain}"
## uri of exposed nginx upstream status with format csv
nginx_upstream_uri="/lb?format=csv"
interval=1
function print_usage() {
cat <<EOF
Usage: ${0} [-h|-H <lb_host>|-e <environment>|-n <seconds>|-p <proto>|-s <nginx upstream csv stub>]
-h Halp.
-H nginx lb host - host.example.com. Default: ${lb_host}
-e Environment. Default: ${environment}
-n Update interval. Default: ${interval}
-p Protocol. Default: ${proto}
-s Nginx upstream status stub in format csv. Default: ${nginx_upstream_uri}
Example:
${0}
${0} -n 5
EOF
}
while getopts hH:e: o
do
case $o in
h)
print_usage ;;
H)
lb_host=$OPTARG ;;
e)
environment=$OPTARG ;;
n)
interval=$OPTARG ;;
p)
proto=$OPTARG ;;
esac
done
shift $(($OPTIND-1))
case $environment in
"dev"|"test"|"prod")
header="${domain^} ${environment^} Environment: LB status" ;;
*)
echo "Unknown environment ${environment}. Exiting..."
exit 1
;;
esac
while :;
do
# XXX: align fields properly...
printf "%s\n" "${header:-}"
printf "id\tpool\tserver:port\tstatus\trise\tfall\tport\n"
curl -k -s ${proto}://${lb_host}${nginx_upstream_uri} | sed 's/,/\t/g'
sleep ${interval}
printf '\033c'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment