#!/bin/bash # Nick's bash script to create CPU gauges from AWS CloudWatch # Source: http://www.linickx.com/archives/3153/amazon-cloudwatch-cpu-gauge # Setup some Time Variables NowMins=`date "+%M"` NowHrs=`date "+%H"` Today=`date "+%Y-%m-%d"` # The last five minute reading is avilable every ten mintues FiveMinsAgo=$(($NowMins - 10)) # If our calcualtion is a negative number correct hours and minutes if [ $FiveMinsAgo -lt 0 ] then FiveMinsAgo=$(($FiveMinsAgo + 60)) NowHrs=$(($NowHrs - 1)) fi # Re-Apply leading zero that gets dropped by calculations if [ $FiveMinsAgo -lt 10 ] then FiveMinsAgo="0"$FiveMinsAgo fi #Formate Start Time for API Tools StartTime=$Today"T"$NowHrs":"$FiveMinsAgo":00.000Z" # Get Results from API Tools Result=`mon-get-stats CPUUtilization --namespace "AWS/EC2" --statistics "Maximum" --dimensions "InstanceId=i-123456" --start-time $StartTime ` Percent=`echo $Result | awk '{print $3}'` Chart="https://chart.googleapis.com/chart?chs=200x125&cht=gom&chd=t:"$Percent"&chl="$Percent"%&chco=00AA0066,FF804066,AA000066&chf=bg,s,FFFFFF00" curl $Chart -o cpu.png