AWS
EC2
Cloud Monitoring
Memory Usage
DevOps

How to monitor EC2 instances by memory?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

EC2 does not publish memory usage to CloudWatch by default. If you want to monitor EC2 instances by memory, you need an agent inside the instance, and the standard AWS answer is the CloudWatch agent.

Why Memory Is Not Available by Default

CloudWatch automatically provides instance-level metrics such as CPU, network, and disk activity because those can be observed from the infrastructure layer. Memory usage is an operating-system-level metric, so AWS needs help from software running inside the guest.

That is why “EC2 memory monitoring” really means “install something in the instance that emits memory metrics.”

Use the CloudWatch Agent

The usual AWS approach is the CloudWatch agent. Once installed and configured, it can publish memory statistics along with other OS-level metrics.

A typical configuration includes a memory section such as:

json
1{
2  "metrics": {
3    "metrics_collected": {
4      "mem": {
5        "measurement": ["mem_used_percent"]
6      }
7    }
8  }
9}

After the agent starts, CloudWatch can alarm on those custom instance memory metrics.

Alarm on the Published Metric

Once memory is in CloudWatch, treat it like any other metric:

  • create dashboards
  • add alarms
  • wire notifications to SNS
  • use the signal for autoscaling or operations response if appropriate

The key operational milestone is not just “metric exists,” but “alerts and dashboards are actually using it.”

Common Pitfalls

  • Expecting EC2 memory usage to appear in CloudWatch automatically without an in-instance agent.
  • Installing the agent but forgetting to configure memory metrics specifically.
  • Publishing the metric but never creating alarms or dashboards for it.
  • Assuming CPU pressure always correlates with memory pressure.
  • Treating one memory percentage number as sufficient without considering swap, application behavior, and workload context.

Summary

  • EC2 memory is not a default CloudWatch metric.
  • You need an in-instance agent, typically the CloudWatch agent.
  • Configure the agent to publish memory metrics such as used percent.
  • Once published, monitor and alarm on those metrics like any other CloudWatch signal.
  • Effective memory monitoring is agent setup plus operational use, not just metric collection.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.