lwftmg
Last Updated: February 25, 2016
·
2.97K
· tralamazza

CloudWatch Disk Utilization

CloudWatch Disk Utilization

As of today, July 3rd 2013, Amazon CloudWatch does not offer disk metrics by default. Thankfully you can add custom metrics using these scripts.

Installation

Log into the machine to be monitored and execute the following:

sudo apt-get install unzip libwww-perl libcrypt-ssleay-perl
wget http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zip
unzip CloudWatchMonitoringScripts-v1.1.0.zip
rm CloudWatchMonitoringScripts-v1.1.0.zip
cd aws-scripts-mon

Sending a custom metric to CloudWatch requires either an API key/secret or a CloudWatch IAM role assigned to the monitored machine.

Case 1: Using credentials (API key/secret)

Inside the ~/aws-scripts-mon folder:

cp awscreds.template awscreds
vim awscreds
crontab -e

Add the following line to crontab, save and exit.

*/5 * * * * $HOME/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --swap-util --disk-path=/ --from-cron --aws-credential-file=$HOME/aws-scripts-mon/awscreds

Case 2: Using IAM role

Note: You must select the appropriate IAM role when launching the EC2 instance, you cannot change it afterwards.

crontab -e

Add the following line to crontab, save and exit.

*/5 * * * * $HOME/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --swap-util --disk-path=/ --from-cron

Important

Make sure your API key/secret has write access to CloudWatch, else you might see a message like this one in your syslog (/var/log/syslog on ubuntu):

Failed to call CloudWatch: HTTP 403. Message: User: ... is not authorized to perform: cloudwatch:PutMetricData

You can add the CloudWatch Full Access policy permission to your user to fix it.

Using them Metrics

After a couple of minutes (at least 5) you will be able to add alarms with your new custom metrics under the name "System/Linux..."