How to configure scripts for getting custom cloud watch metrics :
Amazon Web Services reports some good metrics on the console by default, like CPU, but it's missing some key metrics like memory usage or disk space; these are important to monitor to ensure instance uptime and health. It's a good idea keeping everything in the same place, so we can leave CPU and all the other default metrics as they are, but in addition append the extra ones we want, like how much disk space we have, or how much memory is being used.
These monitoring scripts are authored by Amazon themselves.
Installing prerequisites on the instance:
The monitoring scripts used require some additional Perl libraries to be installed on your Linux instance image. Some operating systems already have certain modules installed by default; run the commands below for a general guide.
For Ubuntu run
sudo apt-get update
sudo apt-get install libwww-perl libdatetime-perl
For RHEL based systems run
sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA
For SUSE Linux Enterprise run
sudo zypper install perl-Switch perl-DateTime "perl(LWP::Protocol::https)"
Please note, If you don't have the unzip package installed on your server, you will also need this in order to unzip the contents of the monitoring scripts. On pretty much every Linux system, this is simply called ‘unzip’.
For Ubuntu run
sudo apt-get update
sudo apt-get install unzip
For RHEL run
sudo yum install zip unzip
For SUSE run
sudo zypper install unzip
Installing the monitoring scripts on the instance.
Run the command below to fetch a zip folder of the monitoring scripts from Amazon.
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
Unzip the contents and remove the zip folder that was just downloaded.
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm CloudWatchMonitoringScripts-1.2.1.zip
Move the folder to the desired location, we'll move this to the below location.
mv aws-scripts-mon .aws-scripts-mon
Navigate to the new folder
cd .aws-scripts-mon
Copy the AWS creds template to a new file
cp awscreds.template credentials.conf
Add the content below to the file
AWSAccessKeyId=[YOUR ACCESS KEY ID]
AWSSecretKey=[YOUR SECRET KEY]
To create a new cron run the following command
crontab -e
Create a new cron job with the following content replacing [USER] with your linux username.
*/5 * * * * ~/.aws-scripts-mon/mon-put-instance-data.pl --aws-credential-file="/home/[USER]/.aws-scripts-mon/credentials.conf" --mem-util --mem-used --disk-space-util --disk-path=/ --from-cron
This cron job will run every 5 mins, sending memory utilisation, the amount of memory being currently used, and the disk space utilisation metrics to Cloudwatch.
Doing something with the data:
Log into your AWS console, navigating to Cloudwatch and ensuring the correct region is selected.
Choose browse metrics.
You should now see Linux System under custom namespaces
Choose instance ID, and you will see a list of the new memory and disk metrics against your Instance ID.
Clicking on a metric will graph the data. If you've just set this up, there won't be much data to graph.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------