Logo Dark
Get in Touch

Custom EC2 CloudWatch Metrics For Memory and Disk Utilization

Written by Nishant Parmar
Published09 August 2024
Tech
Set up custom CloudWatch metrics for your EC2 instances to monitor memory and disk utilization. Simplify your resource management with ease.

Table of contents

Custom EC2 CloudWatch Metrics for Memory and Disk Utilization

  1. Memory (RAM) Usage.
  2. Disk Usage.

E C2 Instance Monitoring

What is a CloudWatch Agent?

Create Role for EC2 Instance

  1. Go to IAM → Roles → Create Role → AWS Service → EC2 → Select `CloudWatchAgentServerPolicy` → Name: CloudWatchAgentRole → Create.
Cloud Watch Agent Server Policy

Configure CloudWatchAgent on EC2 instance

  1. SSH to your EC2 instance and run the following script to install the cloudwatch agent. (Here I am using Ubuntu Server)
Wget

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

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

sudo apt-get update

  • Edit amazon-cloudwatch-agent.json file: sudo nano /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
  • Copy the following script in .json file.
{
   "agent": {
   "metrics_collection_interval": 60,
   "run_as_user": "cwagent"
 },
 "metrics": {
   "append_dimensions": {
       "InstanceId": "${aws:InstanceId}"
   },
   "metrics_collected": {
     "disk": {
       "measurement": [
         "used_percent"
       ],
       "metrics_collection_interval": 60,
       "resources": [
         "/"
       ]
     },
     "mem": {
       "measurement": [
         "mem_used_percent"
       ],
       "metrics_collection_interval": 60
     }
   }

3
amazon-cloud watch-agent.log

Custom Cloud Watch Metrics

References

  1. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html
  2. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html

More

An interesting read? Here is more related to it.

We Make pixel perfect things

We Make pixel perfect things

We Make pixel perfect things

We Make pixel perfect things

We Make pixel perfect things

We Make pixel perfect things

India (HQ)

201, iSquare Corporate Park, Science City Road, Ahmedabad-380060, Gujarat, India

Canada

24 Merlot Court, Timberlea, NS B3T 0C2, Canada

For Sales

[email protected]

Looking For Jobs

Apply Now

LinkedIn
Instagram
X
Facebook
Youtube
Discord
Dribbble
Behance
Github