Last active
May 3, 2020 21:58
-
-
Save mheadd/2106b5a77f052f9935b979104f5b920e to your computer and use it in GitHub Desktop.
Get usage stats for a cloud.gov application
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 | |
# | |
# 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' |
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 | |
# | |
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
get-app-guid.sh
script can probably be replace by just doing: