I want to send memory and disk metrics from my Amazon Elastic Compute Cloud (Amazon EC2) instances to Amazon CloudWatch Metrics.
Short description
By default, Amazon EC2 delivers a set of metrics related to your instance to CloudWatch in the AWS/EC2 namespace. This includes CPU utilization and a set of NetworkIn and NetworkOut metrics.
Amazon EC2 doesn't provide metrics related to operating system (OS)-level memory usage or disk usage metrics. To find these metrics and send them to CloudWatch as custom metrics, install the unified CloudWatch agent. Then, define these metrics in the agent configuration file.
Note: AWS charges custom metrics according to their storage and API use.
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Use the AWS CLI to download and install the CloudWatch agent manually. Or, integrate the CloudWatch agent with AWS Systems Manager Agent (SSM Agent).
Note: The CloudWatch agent is supported on both Windows and Linux systems.
To install the CloudWatch agent, complete the following steps:
-
Create AWS Identity and Access Management (IAM) roles or users that give permissions to the agent that collects metrics from the server. You can also integrate with Systems Manager. Attach the IAM role to the EC2 instance that you want to install the agent on.
-
Download and install the agent package.
-
Create the CloudWatch agent configuration file, and then specify the metrics that you want to collect.
The following are code examples for a basic agent configuration file that reports memory usage and disk usage metrics:
Linux
{
"metrics": {
"metrics_collected": {
"mem": {
"measurement": [
"mem_used_percent"
]
},
"disk": {
"measurement": [
"used_percent"
],
"resources": [
"*"
]
}
},
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
}
}
}
Windows
{
"metrics": {
"metrics_collected": {
"LogicalDisk": {
"measurement": [
"% Free Space"
],
"resources": [
"*"
]
},
"Memory": {
"measurement": [
"% Committed Bytes In Use"
]
}
},
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
}
}
}
-
Start the agent on your EC2 instance.
By default, the active agent reports metrics from your instance to the CWAgent namespace within CloudWatch. If you receive errors, then see Troubleshooting the CloudWatch agent.
Related information
Monitor your instances using CloudWatch