Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor EC2 instances by memory?

Using Cloudwatch you can monitor your EC2 instances by several criteria, such as network usage, CPU usage, and so on…

Unfortunately, there is no metric for memory consumption. First of all, just out of curiosity, I would like to know, why? Can anybody explain why it is possible to, e.g., monitor CPU usage, but not memory usage? At least to me, that's not obvious.

And then, my actual question: Okay, given that Cloudwatch doesn't allow monitoring the EC2 instances' memory usage - what is the alternative? How should I setup an alarm if, e.g. > 80% of the memory of an instance is being used?

like image 506
Golo Roden Avatar asked Feb 18 '17 15:02

Golo Roden


People also ask

How do I monitor my EC2 instance memory?

Simply go to the CloudWatch dashboard in your AWS console and click on Metrics. You'll see a new CWAgent card. After you click on this card, you should see your EC2 memory usage in a graph. Be sure to give it some time for the collection process to start properly.

How do I enable memory metrics in CloudWatch for EC2?

Use these steps to install the CloudWatch agent: 1. Create IAM roles or users that enable the agent to collect metrics from the server and, optionally, integrate with AWS Systems Manager. Attach this IAM role to the EC2 instance that you want to install the agent on.

How much RAM does an EC2 instance have?

Amazon EC2 High Memory instances have the highest amount of memory of any EC2 instance with up to 24 TiB of memory. These instances are purpose-built for large in-memory databases like SAP HANA.


2 Answers

Memory and Disk specific statistics require AWS to monitor at the OS level rather than the host level, so that is why they leave it out by default. It will probably be added at some point but since it has been on the wish list for about 7 years, we can assume it's a very low priority item.

The recommended way to monitor memory usage is to create a custom Cloudwatch metric by using your own monitoring scripts on your instances. AWS have published documentation on how to achieve this on Linux instances with a set of (unsupported) scripts.

Once your instances are publishing the custom metrics, you will be able to attach alarms to them in CloudWatch.

like image 79
DF_ Avatar answered Sep 23 '22 15:09

DF_


Well, now the new CloudWatch agent can collect metrics like memory and disk usage, see the docs.

With this you can monitor this kind of metrics, but you will need to install and configure the agent in the instances.

like image 28
dpolicastro Avatar answered Sep 20 '22 15:09

dpolicastro