by znep · 9y ago · 0 comments
I have a hacky shell script I sometimes use for moderately sized environments that don't have better monitoring setup, it reports the minimum percent of burst balance remaining over the past day, requires the aws cli and parallel:
#!/bin/bash
while getopts "p:" opt; do
case $opt in
p)
export AWS_PROFILE=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
if [ ! "$AWS_PROFILE" ]
then
echo "-p <aws profile> or AWS_PROFILE env var required"
exit 1
fi
start=$(date -v-1d +%Y-%m-%dT%H:%M:%S)
end=$(date +%Y-%m-%dT%H:%M:%S)
aws ec2 describe-volumes --output text --query 'join(`"\n"`, Volumes[*].VolumeId)' | parallel -j 20 "echo -ne {}\\\t && echo \$(aws cloudwatch get-metric-statistics --start-time $start --end-time $end --period 86400 --namespace AWS/EBS --statistics Minimum --metric-name BurstBalance --dimensions Name=VolumeId,Value={} --output text --query 'Datapoints[*].Minimum')" | sort -n -k 2