Linux | Installation of custom AWS metrics script & prerequisites for AMI

Author - Navneet Kashyap

1.  Login to Amazon Linux-AMI / Centos / RedHat:

Using ssh

2.  To Upgrade from a previous version of the scripts:

# sudo yum install perl-DateTime

3.  To install the scripts for the first time:

# sudo yum install perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https

4.  Download & Unzip the script in /home/monitor/ :

# wget http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
# unzip CloudWatchMonitoringScripts-1.2.1.zip
# rm CloudWatchMonitoringScripts-1.2.1.zip

5.  Using the Scripts mon-put-instance-data.pl (it collects memory, swap & disk space utilization data on the current system):

# cd aws-scripts-mon

5.1. Rename awscreds.sample to awscreds.conf:

# mv awscreds.sample awscreds.conf

5.2. Edit awscreds.conf and provide correct aws authorized access ID and secretkey:

# vi /home/monitor/aws-scripts-mon/awscreds.conf
AWSAccessKeyId=*************
AWSSecretKey=*****************

5.3. Perform a simple test run without posting data to CloudWatch:

# perl /home/monitor/aws-scripts-mon/mon-put-instance-data.pl --mem-util --verify --verbose --aws-credential-file=/home/monitor/aws-scripts-mon/awscreds.conf

Once the verification is done it will display below message:

Verification completed successfully. But No actual metrics sent to CloudWatch.

5.4. Collect all available memory metrics and send them to CloudWatch:

# perl /home/monitor/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --verbose --aws-credential-file=/home/monitor/aws-scripts-mon/awscreds.conf

Once the command is executed it shows below success message:

Successfully reported metrics to CloudWatch. Reference Id: 5d2c023b-82d8-11e5-bc d7-a5ddde77631e

5.5. And for any additional volume is attached to the machine.

You just need to edit the above command for disk path like /mnt/archive:

# perl /home/monitor/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/mnt/archive --verbose --aws-credential-file=/home/monitor/aws-scripts-mon/awscreds.conf

6. Crontab to schedule it run every 5 min:

# vi /etc/crontab
*/5 * * * * root perl /home/monitor/aws-scripts-mon/mon-put-instance-data.pl –mem-util –disk-space-util –disk-path=/mnt/archive –verbose –aws-credential-file=/home/monitor/aws-scripts-mon/awscreds.conf

7.  Now you can check custom metrics results in AWS CloudWatch Service:

Click on Metrics option from left pane then click on Linux System Metrics: (which is showing the number of custom alerts configured successfully)

Select any Instance name and then monitor it by setting threshold limits according to your requirements. Like Alerts when disk size exceeded 80% of total space.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *