In this tutorial we teach how to use SSM to monitor memory and swap in AWS integrated with “Best Practices”.
1 – Installation of the CloudWatch Agent on EC2 instances.
Instructions on how to install the CloudWatch Agent, configuration file, roles and permissions are at the link below:
2 – Checking metrics on CloudWatch.
The list of metrics collected by the CloudWatch Agent are in the link below, as created in the CloudWatch Agent configuration file:
For example, for Linux servers, to view the percentage of memory and swap used, simply view the metrics mem_used_percent and swap_used_percent , within the CWAgent namespace in CloudWatch metrics. These metrics are used in the rules in the MP.
Below we see an example of a Linux server with the mem_used_percent metric:
3 – Configuration of memory and swap monitoring rules in Melhores Prátticas.
After CloudWatch Agent configurations, we can configure rules in Best Practices to alert about memory or swap consumption.
We can change the pre-configured threshold in the rules, customizing the filter in the settings. To do this, let’s follow the steps:
3.1 – Standard configuration:
As an example, let’s open the memory monitoring rule settings:
By default, Best Practices will alert EC2 instances that have metrics collected by the CloudWatch Agent with 90% memory used on 5 or more days.
3.2 – Customization:
Let’s customize by clicking on the “Customize” option and making this configuration more flexible:
In this case we want Best Practices to alert memory consumption equal to or greater than 60% in 3 or more days. To do this, we have to customize the settings as follows:
3.3 – Result:
After applying the settings, and later when the rule is executed, we can see the result: