Steps To Monitor Memory Utilization of EC2 Instance with CloudWatch¶
Monitoring system performance is crucial for maintaining optimal performance. Amazon Web Services (AWS) provides a powerful monitoring service called CloudWatch, which allows you to monitor various metrics of your EC2 instances, including CPU, memory, and disk utilization. In this blog post, we'll discuss how to set up monitoring for these metrics using CloudWatch.
Prerequisites:¶
- IAM Role with “CloudWatchFullAccess”
- Assign IAM Role to EC2 Instance
Installing CloudWatch Agent¶
First, log in to the EC2 instance, and download and install the CloudWatch agent.
After installing CloudWatch Agent, create config.json
file at /opt/aws/amazon-cloudwatch-agent/bin/config.json
Enter the below text in the config.json
file.
{
"metrics": {
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
},
"metrics_collected": {
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"disk": {
"measurement": [
"disk_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
With the below command, we can start the CloudWatch 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
The above command output should be like below.
Then execute below command to run the CloudWatch Agent.
With the below command, we can check status of the CloudWatch Agent.
Verifying that the Amazon CloudWatch Agent is working involves checking if it's successfully collecting and sending metrics to CloudWatch.
- Navigate to the CloudWatch service.
- Go to the Metrics section.
- You will get metrics of your instance.
Conclusion:¶
Monitoring CPU, memory, and disk utilization is essential for maintaining the performance and health of your AWS infrastructure. By leveraging AWS CloudWatch, you can easily collect, visualize, and analyze these metrics, enabling you to make informed decisions and ensure optimal resource utilization. Follow the steps outlined in this blog post to configure monitoring for your EC2 instances and start harnessing the power of CloudWatch today!
References:¶
- AWS CloudWatch Documentation: https://docs.aws.amazon.com/cloudwatch/index.html
- AWS CloudWatch Agent Setup Guide: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-first-instance.html
- AWS CloudWatch Alarms Guide: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html