Why don't EC2 CloudWatch Metrics Show Memory and Disk Utilization metrics by default?
Tags: aws, devops, cloudwatch, monitoring
Published: 2024-03-05 02:12:15



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w15lhm8cojne7dc7yd7u.png)


To understand that, you need to understand the difference between hypervisor and OS-level metrics.



🖥️ Virtualization and the Hypervisor:

To understand the distinction, you first need to grasp the basics of virtualization. Virtualization allows multiple virtual machines (VMs), including EC2 instances in the case of AWS, to run on a single physical machine. The component responsible for this is called the hypervisor.

The hypervisor sits between the hardware and the operating systems of the VMs. It allocates resources like CPU, memory, and I/O to the VMs, ensuring they don't interfere with each other.



📊 Hypervisor-Level Metrics vs. OS-Level Metrics:



✅ Hypervisor-Level Metrics: These are metrics that the hypervisor can observe directly without needing to interact with the guest operating systems (the OSes running inside the VMs). Example:

1️⃣ CPU utilization: The hypervisor manages CPU allocation and can measure how much CPU time is allocated to each VM.

2️⃣ Disk I/O: Similarly, disk reads/the hypervisor manages writes to measure these metrics directly.

3️⃣ Network: Network packets go through the hypervisor, allowing it to measure network activity.



✅ OS-Level Metrics: These metrics relate to what's happening inside the virtual machine's operating system. The hypervisor doesn't have direct access to these metrics because they are encapsulated within the VM. Example:

1️⃣ 🧠 Memory Usage: While the hypervisor allocates a certain amount of memory to a VM, it doesn't see how that memory is used inside the VM. For instance, the hypervisor doesn't know which processes within the VM are consuming the most memory or if there's free memory available.

2️⃣ 💾 Disk Space: The hypervisor can observe how much data is read/written, but it doesn't know the available disk space or how it's partitioned within the VM's file system.



🛠️ How to get memory and disk space metrics into CloudWatch:

While AWS doesn't provide these metrics by default, they've made it possible for users to push custom metrics to CloudWatch. The CloudWatch agent can collect additional system-level metrics, including memory and disk space usage.

When you deploy the CloudWatch agent on an EC2 instance, the agent runs as a background service. It gathers the specified system-level metrics at defined intervals and sends them to CloudWatch using the PutMetricData API call. The agent is configurable, allowing you to specify which metrics to collect, the granularity of the data, and how frequently to send it to CloudWatch.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk2n4k4wz2419tsyag3d.jpg)

📚 If you're interested in more in-depth explanation of these topics, please check out my new book “Cracking the DevOps Interview”

https://pratimuniyal.gumroad.com/l/cracking-the-devops-interview

📚 content:  https://github.com/100daysofdevops/Cracking-the-devops-interview-code/blob/main/book-content 
To learn more about AWS, check out my book “AWS for System Administrators”
https://www.amazon.com/AWS-System-Administrators-automate-infrastructure/dp/1800201532/?_encoding=UTF8&pd_rd_w=xI51B&content-id=amzn1.sym.d0ebfbb2-6761-494f-8e2f-95743b37c35c%3Aamzn1.symc.50e00d6c-ec8b-42ef-bb15-298531ab4497&pf_rd_p=d0ebfbb2-6761-494f-8e2f-95743b37c35c&pf_rd_r=QP32TXADHZCEEW0GVVM3&pd_rd_wg=3LIjA&pd_rd_r=7d15b19d-2da7-4d1e-8782-5880812cc2a4&ref_=pd_gw_ci_mcx_mr_hp_atf_m