How can I send memory and disk metrics from my EC2 instances to CloudWatch?
I want to send memory and disk metrics from my Amazon Elastic Compute Cloud (Amazon EC2) instances to Amazon CloudWatch Metrics. How can I do this?
"I want to send memory and disk metrics from my Amazon Elastic Compute Cloud (Amazon EC2) instances to Amazon CloudWatch Metrics. How can I do this?Short descriptionBy default, Amazon EC2 delivers a set of metrics related to your instance to CloudWatch in the AWS/EC2 namespace. This includes CPUUtilization, a set of disk Read and Write metrics, and a set of NetworkIn and NetworkOut metrics. But, EC2 doesn't provide metrics related to OS-level memory usage or disk usage metrics.To find these metrics and deliver them to CloudWatch as custom metrics, install the Unified CloudWatch Agent. Then, define these metrics in the Agent configuration file.Important: Custom metrics are charged according to their storage and API use.ResolutionNote: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.You can download and install the CloudWatch agent manually using the AWS CLI or you can integrate it with AWS Systems Manager Agent (SSM Agent). The CloudWatch agent is supported on both Linux and Windows systems. 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.2.    Download the agent package and install the agent package.3.    Create the CloudWatch agent configuration file and specify the metrics that you want to collect.This example shows a basic agent configuration file that reports memory usage and disk usage metrics on a Linux system:{  "metrics": {    "metrics_collected": {      "mem": {        "measurement": [          "mem_used_percent"        ]      },      "disk": {        "measurement": [          "used_percent"        ],        "resources": [          "*"        ]      }    },    "append_dimensions": {      "InstanceId": "${aws:InstanceId}"    }  }}This is an example of a basic agent configuration file for Windows systems:{  "metrics": {    "metrics_collected": {      "LogicalDisk": {        "measurement": [          "% Free Space"        ],        "resources": [          "*"        ]      },      "Memory": {        "measurement": [          "% Committed Bytes In Use"        ]      }    },    "append_dimensions": {      "InstanceId": "${aws:InstanceId}"    }  }}4.    Start the agent on your EC2 instance.When the agent is running, it reports metrics from your instance to the CWAgent namespace within CloudWatch, by default. If you experience issues, see Troubleshooting the CloudWatch agent.Related informationMonitor your instances using CloudWatchFollow"