This is a guide to setting up memory and disk utilization monitoring in CloudWatch. This is not something that is natively supported by CloudWatch and requires some special setup on the instances that you would like to monitor.
When I was attempting to do this for the first time, I found that some of the instructions both from Amazon and around the web were lacking or missing pieces, especially, if you like me are trying to do this installation on Centos 6.
Install the Prerequisite YUM Packages
Run the following commands to install the required YUM packages:
sudo yum install -y perl-DateTime perl-New-SSLeay perl-IO-Socket-SSL perl-Digest-SHA gcc sudo yum install -y zip unzip sudo yum install -y perl-CPAN Install Perl packages via CPAN
You will need to run CPAN as an elevated user, so: sudo cpan. If this is your first time running CPAN you will get prompted at least once, if not more to configure it. Just press enter to accept the defaults.
Next you will need to install the following packages one at a time:
install YAML install LWP::Protocol::https install Sys::Syslog install Switch As you are installing these CPAN will likely prompt you to install dependencies and/or run tests. Just press enter to accept the defaults.
Install the monitoring scripts
Now it is time to actually get and install the scripts. You can run them from anywhere on the filesystem that you like, however, I recommend using a subdirectory of /opt and that is the convention that I have assumed for this guide.
First, create your directory and then change to it:
sudo mkdir -p /opt/monitor && sudo chown
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O unzip CloudWatchMonitoringScripts-1.2.1.zip rm CloudWatchMonitoringScripts-1.2.1.zip cd aws-scripts-mon Verify that the script is able to run correctly
You are going to want to run the following command to validate that the script is installed correctly and that you have the appropriate credentials to push the data to CloudWatch. [^1]
./mon-put-instance-data.pl --mem-util --swap-util --disk-path=/ --disk-space-util --verify --verbose This output should indicate that the verification passed. If so, you are ready to move to scheduling it to run and post the data to CloudWatch.
Setup continuous monitoring
The best way I have found to have continued monitoring from the script is to create a cron job
- /opt/monitor/aws-scripts-mon/mon-put-instance-data.pl --mem-util --swap-util --disk-path=/ --disk-space-util --from-cron The cron job entry above will post the data to CloudWatch every minute. Including the --from-cron option will suppress the normal output from the script.
[^1]: There are several different ways that you can setup the credentials. However, the way that is recommended and the way that I find to be the easiest, is to assign an IAM role with the appropriate permissions to the EC2 instance(s) that you are going to run the monitoring script on.