Skip to content

Instantly share code, notes, and snippets.

@mheadd
Last active May 3, 2020 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheadd/2106b5a77f052f9935b979104f5b920e to your computer and use it in GitHub Desktop.
Save mheadd/2106b5a77f052f9935b979104f5b920e to your computer and use it in GitHub Desktop.
Get usage stats for a cloud.gov application
#!/bin/bash
#
# A simple script to get a GUID for an applications. Note - assumes you have jq installed.
#
# The GUID for the app you want to check
APP_NAME=$1
if [[ ! $(which jq) ]]; then
echo "Error: You must have the jq utility installed to run this script. https://stedolan.github.io/jq/" >&2
exit 1
fi
if [[ ! $1 ]]; then
echo "Error: You must supply an app name." >&2
exit 1
fi
cf curl "/v2/apps" -X GET -H "Content-Type: application/x-www-form-urlencoded" -d "q=name:$APP_NAME" | jq '.resources | .[].metadata | .guid'
#!/bin/bash
#
# A simple script to check on usage stats for a cloud.gov app. Note - assumes you have jq installed.
#
# The GUID for the app you want to check
APP_GUID=$1
if [[ ! $(which jq) ]]; then
echo "Error: You must have the jq utility installed to run this script. https://stedolan.github.io/jq/" >&2
exit 1
fi
if [[ ! $APP_GUID ]]; then
echo "Error: You must pass in an app GUID when invoking this script"
exit 1
fi
MEM_UTIL=$(printf '%.*f\n' 2 $(cf curl "/v2/apps/$APP_GUID/stats" | jq '((.[].stats | .usage | .mem) / (.[].stats | .mem_quota)*100)'))
DISK_UTIL=$(printf '%.*f\n' 2 $(cf curl "/v2/apps/$APP_GUID/stats" | jq '((.[].stats | .usage | .disk) / (.[].stats | .disk_quota)*100)'))
echo -e "\n"
echo "Usage stats for app: $APP_GUID"
echo "------------------------------------------"
echo "Allocated memory utilization: $MEM_UTIL"
echo "Allocated disk utilization: $DISK_UTIL"
echo -e "\n\n"
@mheadd
Copy link
Author

mheadd commented Apr 23, 2020

The get-app-guid.sh script can probably be replace by just doing:

~$ cf app <APP_NAME> --guid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment