Skip to content

Instantly share code, notes, and snippets.

@quangthe
Last active March 26, 2019 02:56
Show Gist options
  • Save quangthe/21d6a00ddced3a8dd600af0c1497156a to your computer and use it in GitHub Desktop.
Save quangthe/21d6a00ddced3a8dd600af0c1497156a to your computer and use it in GitHub Desktop.
Query AWS RDS free storage
usage()
{
echo "usage: get-rds-free-storage.sh -i instance -r region"
}
REGION="ap-southeast-1"
START="$(date -v '-5M' -u '+%Y-%m-%dT%H:%M:%SZ')" # 5 minutes ago
END="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
INSTANCE_NAME="mydb"
while [ "$1" != "" ]; do
case $1 in
-r | --region ) shift
REGION=$1
;;
-i | --instance ) shift
INSTANCE_NAME=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
AWS_DEFAULT_REGION="$REGION" aws cloudwatch get-metric-statistics \
--namespace AWS/RDS --metric-name FreeStorageSpace \
--start-time $START --end-time $END --period 300 \
--statistics Average \
--dimensions "Name=DBInstanceIdentifier, Value=${INSTANCE_NAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment