How to Use CloudWatch Monitoring Scripts to Monitor an EC2 Linux Instance

How to Use CloudWatch Monitoring Scripts to Monitor an EC2 Linux Instance

Amazon CloudWatch provides monitoring for the AWS cloud resources and the applications customers run on AWS. Developers and system administrators can use it to collect and track metrics, gain insights, and give immediate responses for the smooth functioning of the applications and businesses.

The Amazon CloudWatch Monitoring Scripts for Linux are sample Perl scripts that demonstrate how to produce and consume the Amazon CloudWatch custom metrics. This guide demonstrates how to setup and use the CloudWatch Monitoring Scripts for the user’s Linux instance.

1. Launch a Linux instance and connect to the instance.

2. Before installing the monitoring tool, it is necessary to  perform certain additional steps.  Based on the version of Linux the below mentioned steps may be different.  The steps for AWS Linux are described below.

3. Go to the root directory with the command “cd\”. Update the Perl version of Linux with the command “perl -vsudo yum update”.

4. Some versions of Linux require additional dependencies. Install the dependencies with the following command:

sudo yum install perl-Time-HiRes

[Newvem helps you to discover how your cloud resources are utilized, learn utilization changes on an hourly basis, look back into historical usage patterns and determine how your consumption is trending. Learn More]

5. Further, also install the other dependencies with the following commands:

sudo yum install -y perl-CPAN
sudo yum install -y make
sudo yum install -y perl-XML-Parser
sudo yum install -y mod_perl

6. Run the command “perl -MCPAN -e shell” to install the CPAN packages.

7. Install the bundle CPANXXL with the command “install Bundle::CPANxxl “[The command may take about 10-15 minutes].

8. Install the prerequisite package for CloudWatch monitoring with the command “install Bundle::LWP5_837 LWP”.

9. Exit from CPAN and run the commands to download the script.

10. Create a directory to store the monitoring script.

sudo mkdir aws-scripts-mon
cd aws-scripts-mon

11. Download the monitoring scripts from the URL using the command:

sudo wget

Unzip the file with the following command:

sudo unzip

12. The directory will contain the monitoring scripts as well as the file to set the AWS credentials.  Edit the file awscreds.conf with the user’s AWS account Access and Secret Access key.

13. Test your setup with the following command:

./ --mem-util --verify –verbose

14. To send the instance data to the AWS CloudWatch, use the following command:

./ --mem-util --mem-used --mem-avail

15. To view the data sent to CloudWatch, go to the AWS CloudWatch dashboard and select to view the specific instance metrics.

16. Select “System/Linux:InstanceId” from the viewing.

17. Select from the available metrics, which will demonstrate the data sent from the Linux instance.

[Newvem analytics tracks you AWS cloud utilization:

  • Hourly Utilization Pattern Analysis 
  • Reserved Instances Decision Tool 
  • Resource Resizing Opportunities

Create Your Free Newvem Account or Learn more about Newvem]

Keywords: Amazon web services, Amazon AWS console, Amazon AWS instances, EC2 Service, Amazon cloud computing, EC2 EBS, EC2 CPU Utilization, Amazon EC2 capacity, Cloud Monitoring, CloudWatch, API, CLI tools, CloudWatch Alarm, CloudWatch Custom Metrics

Enchance Your Amazon Cloud Knowledge!

EC2 Resource Automation; Security Groups Management;
S3 Storage Discovery and Management

High Availability Deployment Cases; Cloud Cost Control Best Practices;
Advanced Cloud Security

  • Eric Anderson

    You can skip the script and get more visibility if you use something like CopperEgg, which can also pull in cloudwatch metrics as well, but with a better interface.