Cloudwatch Agent Installation & Configuration

In this example, lets try to use Cloudwatch to monitor the WebApplication logs.

Step #1, is to create a service role, that allows the instance to connect with cloudwatch service. We will attach the AWS managed policy : CloudWatchAgentServerPolicy to the role.

2022-05-29 15_25_30-IAM Management Console.png

Step #2, is to download the cloudwatch agent package for the instance and installation.

docs.aws.amazon.com/AmazonCloudWatch/latest..

In this example, will be using a Ubuntu machine.

wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

2022-05-29 15_39_51-3.25.122.157 (ubuntu).png

Step#3, is to create the agent configuration file using the wizard.

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

2022-05-29 16_22_35-3.25.122.157 (ubuntu).png

In our case, we have a tomcat8 instance running on the server and would like to monitor the log file catalina.out located under /var/log/tomcat8 directory

2022-05-29 16_25_42-3.25.122.157 (ubuntu).png

The output of the wizard is written to a json file : config.json

2022-05-29 16_26_40-3.25.122.157 (ubuntu).png

The final step is to start the agent service.

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

2022-05-29 16_31_40-3.25.122.157 (ubuntu).png

Verify the cloudwatch agent logs at

2022-05-29 16_39_03-3.25.122.157 (ubuntu).png

On successful startup, the logs are now available in cloudwatch console.

2022-05-29 16_43_45-CloudWatch Management Console.png

To filter the logs, use Log Insight

2022-05-29 16_49_23-CloudWatch Management Console.png

Thus you can view the Application Deployment logs using Cloudwatch.