DevOps engineers, developers, site reliability engineers (SREs), and IT managers can use Amazon CloudWatch, monitoring, and observability service, to keep track of their systems. A unified view of operational health is possible with CloudWatch because it gives you data and actionable insights to monitor your applications, react to system-wide performance changes, and optimize resource utilization. Monitoring and operational data in the form of logs, metrics, and events are collected by CloudWatch and provided to you as a unified view of AWS resources, applications, and services that are run both on AWS and on-premise servers. Anomaly detection, alarm setting, log, and metric visualization, automated action, troubleshooting, and insight discovery are all possible with CloudWatch. It helps you keep your applications running smoothly.

AWS Cloudwatch

Customer applications running on the Amazon infrastructure can be monitored with the help of Amazon CloudWatch, a service provided by Amazon Web Services.

Elastic Load Balancing, Amazon Relational Database Service (RDS) instances, Amazon Elastic Compute Cloud (EC2) instances, and Amazon Elastic Block Store (EBS) volumes can all be monitored in real-time with CloudWatch. CPU utilization, latency, and request counts are all tracked automatically by the app. In addition, users can specify metrics such as memory usage, transaction volumes, or error rates to be tracked.

Application programming interfaces (APIs), command-line tools, AWS software development kits, and the AWS Management Console are all ways users can access CloudWatch features. The CloudWatch user interface offers graphs of current statistics for users to peruse at their convenience. Users have the option of configuring notification alarms to be sent when a specified threshold is exceeded by something being monitored. The app can also identify and terminate any EC2 instances that are no longer in use.

AWS users, such as DevOps engineers, IT managers, cloud developers, and site reliability engineers, can use Amazon CloudWatch.

CloudWatch Custom Metrics and Monitoring on Amazon AWS

Custom Metrics for EC2 Monitoring

You may use CloudWatch to keep an eye on your EC2 instances by executing the following commands:

  •  CPU
  •  Network
  •  Disk
  • Status

Please keep in mind that RAM usage is a customer metric. Ec2 monitors for 5-minute intervals by default, unless detailed monitoring is enabled, in which case it will be 1-minute intervals (it will cost more)

We will set up a practice, build an EC2, and then tweak the Cloudwatch Memory measure to fit our needs.

Step 1: We must construct a CloudWatch Role for EC2 in order for EC2 to communicate with CloudWatch and exchange data.

Step 2: Set up an IAM Role called “EC2CloudWatch” by going to IAM

Step 3: Select the Policy CoudWatchFullAccess

Step 4: You should construct an EC2 instance and attach the above role to it. Then you should use some Perl script to configure the Memory Utilization for the instance you’ve just created.

Step 5: Go to Google and type Monitoring Memory and Disk Metrics for EC2 Linux instance before we begin our exercises.

Our first step will be to log into EC2 Linux and then execute the following command in the current directory: cd

Curl -O

Step 6: Now I’ll head over to Amazon Web Services and launch a brand new EC2 instance (Linux)

Step 7: When you first log in to Linux, type these commands into the prompt:

Step 8: We will now proceed to install the Perl script as follows: (install Perl Syslog and Protocols)

sudo yum install -y Perl-Switch Perl-DateTime Perl-Sys-Syslog Perl-LWP-Protocol-HTTPS Perl-Digest-SHA.x86_64

Step 9: For the time being, I’m going to create a directory where we can put all of our files and other data.

Mkdir /cloudwatchlab

Cd /cloudwatchlab

Step 10: Here’s the code we copied from Amazon’s website:

curl -O

Step 11: Now we’re going to unzip it.

Step 12: If we type ls, we can see that the directory AWS-scripts-mon was created.

Now I’m going to delete the Zip file that we downloaded earlier.

rm –rf

Step 13: I open the file cabinet and find the directory

Cd aws-scripts-mon/

After that, simply enter ls to bring up a Perl script (in green color)


Step 14: Prior to submitting these scripts to Ec2, return to the AWS console and check Cloudwatch. You will notice that there is no Metric for Memory, but this will change once the Perl scripts have been submitted.

Step 15: Create a new dashboard and include CPU utilization in it by going to Dashboards > Create New Dashboard (as we see we do not have Memory Utilization)

You may use CloudWatch to keep an eye on your EC2 instances by executing the following commands:

  •  CPU
  •  Network
  •  Disk
  • Status

Step 16: This command was copied and pasted from the AWS websites back into our terminal windows.

I’ll see if our EC2 instance can communicate with CloudWatch by running this line of code.

./ –mem-util –verify –verbose

(Be careful to execute it from the aws-scripts-mon directory.)

As you can see, everything is in order at this point.

The verification process was a success. CloudWatch is not receiving any data.

Step 17: From now on, we’ll keep an eye on RAM usage via cloud monitoring.

Copy and paste

 ./ –mem-used-incl-cache-buff –mem-util –mem-used –mem-avail

As far as success goes, it’s clear

Metrics were successfully sent to CloudWatch.

The following reference number is unique: 37ce5b72-48ae-11e8-800c-6be073b72519

Step 18: When you no longer wish to perform the aforementioned process by hand, you can utilize a concept known as “crontab” to automate it.

Step 19: Obtain a directory, for example

Cd /etc

Then type till you reach the bottom of the page

*/5 * * * * root ./ –mem-used-incl-cache-buff –mem-util –mem-used –mem-avail

Remove in the previous sentence if necessary. Then navigate to the cloudwatchlab/aws-scripts-mon directory you previously created

*/5 * * * * root /cloudwatchlab/aws-scripts-mon

/ –mem-used-incl-cache-buff –mem-util –mem-used –mem-avail

As a reminder, the directory name case is critical.

Save your work before you go.