Reporting memory utilization using the CloudWatch enhanced monitoring scripts

The CloudWatch team has made it easy for us to report metrics with the use of the CloudWatch enhanced monitoring scripts. The script we are going to use in this example will allow us to report memory metrics from the operating system to the CloudWatch environment. The setup is quite straightforward and easy to do with minimal Linux command-line knowledge.

Before we start, we need to make sure we install the prerequisites. On an Amazon Linux instance, all we need to install are a few perl packages as the script is written in perl and requires these to run:

sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64

Next, we need to retrieve and install the monitoring scripts from the repository:

curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O && 
unzip CloudWatchMonitoringScripts-1.2.2.zip &&
rm CloudWatchMonitoringScripts-1.2.2.zip

Once unzipped, a new directory called aws-scripts-mon is created. We will need to enter the aws-scripts-mon directory by running cd aws-scripts-mon and test the monitoring script:

./mon-put-instance-data.pl --mem-util --verify --verbose

This will test if we have all the prerequisites and permissions required to write to CloudWatch. No data will be written during this test, and the response of the test command should look something like this:

If the test has completed successfully, then we can now try to publish our memory metrics to CloudWatch:

./mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --mem-used --mem-avail

The response of the publishing command should look something like the following screenshot:

Once happy with the setup, we can create a cron job that sends the custom metrics to the CloudWatch environment based on your preferences. The following example sends metrics every 5 minutes:

*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.66