Saturday, 29 August 2020

Install Cloudwatch Agent on Ec2 Linux Instance to get the Memory metrics on Cloudwatch

 Cloudwatch:

To monitor AWS resources , we have cloud watch feature.

  • We can monitor all AWS resources/services and our applications
  • By default all AWS resources are configured to publish its metrics to cloud watch.

Cloud watch agent: 

Using this we can monitor customer metrics of AWS resources.

To monitor on premises server we can install cloud watch agent in on premises.

Lets see how we can collect metrics of EC2 instance by using cloudwatch agent. 

Prerequisites to start this task are as below

  1. Linux EC2 instance
  2. IAM role

Create IAM Role as below

Click on Create role as above and select EC2  as below

Click on "Permissions"

click on Review and add Role name as below


Now "Cloudwatchadmin" role is ready.

Lets start creating Amazon Linux EC2 instance 


Create SG like below

and proceed further to accept default values of EC2 and launch the instance.

Now connect EC2 using Putty and download the cloudwatch agent in linux instance.

wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm

Now install the same by using the command

sudo rpm -U ./amazon-cloudwatch-agent.rpm

Configure the cloudwatch agent with the help of setup wizard

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

Now run the cloud watch agent

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s


Open cloudwatch service from AWS dash board

Click on CWAgent and select Imageid,InstanceID,Instance type.
We can see our EC2 instance.


To add these metrics to dashboard, first create dashboard then add it.


Select Line type dashboard as below
Select Metrics as below and click on configure.

Select our ec2 instance like below

Click on CreateWidget.


Now its done for memory metrics at cloud watch by installing cloudwatchagent.

Thank you for reading 👍👍👍👍👍