Cloud Watch - Custom metrics for EC2

What is CloudWatch?

Amazon Web Services  CloudWatch is a powerful tool for optimizing the performance of AWS infrastructure. CloudWatch gathers monitoring and operational data in the form of logs, metrics, and events, and visualizes it using automated dashboards to provide you a single view of all your AWS resources, applications, and services, that are on on-premises and also on cloud. However, CloudWatch doesn’t readily surface all the information you might be looking for. Since AWS does not have access to your OS, some metrics are missing including disk and memory utilization in Gb.

What is CloudWatch Metrics?

Metrics is a specific value over time. In other words, it can be viewed as a variable that we need to monitor our EC2 instances, and the data points represent its values over time. These metrics helps you keep track of your instance performance at specific time intervals. CloudWatch Agent helps collect metrics and logs from EC2 instances and on-premises servers and push them to CloudWatch.

Types of metrics:

Basic Monitoring for EC2

Basic monitoring of an EC2 instance includes CPU load, disk I/O, and network I/O metrics. You probably noticed that one metric that is normally considered a baseline metric to track is missing; EC2 does not expose metrics related to memory. You will need to implement a custom metric to track this. By default, Amazon EC2 sends metric data to CloudWatch in 5-minute intervals. Basic monitoring is free and automatically enabled for all AWS services that support the feature.

Detailed Monitoring for EC2

Detailed monitoring delivers metrics in 1-minute intervals, rather than 5-minute intervals. This provides higher resolution of metrics so that you will be able to know and act on service issues quicker. It brings more enhancements and detailed monitoring for the service. If you enable detailed monitoring, you will be charged for all the metrics that were previously included as part of basic monitoring. Using detailed monitoring for Amazon EC2 helps you better manage your Amazon EC2 resources, so that you can find trends and take action faster.

Custom Metrics

In some cases, we need to create our own metric and push it to CloudWatch to solve our problems. As the default metrics don’t cover all the metrics the user needs, we need to have some specific implementations for them. Custom metrics are metered differently than any of the basic metrics. Some custom metrics are disk space available and memory utilization in Gb.

CloudWatch Pricing for EC2 

Aws do not charge for:

  • Basic Monitoring metrics (at 5-minute frequency)
  • 10 Detailed Monitoring Metrics (at 1-minute frequency)
  • 1 Million API requests

All custom metrics and EC2 Detailed Monitoring is charged by the hour and metered only when the instance sends metrics to CloudWatch. You are charged Monthly $0.30 per custom metric.

STEPS to configure custom metrics:

Create IAM roles for user that enable the agent to collect metrics from the server and to integrate with Amazon Systems Manager.

First, you need to grant your EC2 access to the CloudWatch service.

  • Open the AWS Management Console and go to the IAM service. 
  • Select Roles and choose AWS Service and EC2 as the trusted entity for your IAM role.
    1. Next, you need to add permissions for CloudWatch. Search for CloudWatchAgent and select CloudWatchAgentServerPolicy from the result list. Click the Next button to proceed.
  • After creating role open the EC2 service and select the EC2 instance you want to monitor. Click the Actions button and select Modify IAM role from the Security category.
  1. Choose the IAM role you just created and click the Save button.

Your EC2 instance is now allowed to send CloudWatch metrics.

CloudWatch Agent helps collect metrics and logs from EC2 instances and push them to CloudWatch

  1. After this, you will install CloudWatch agent by referring below link:


  1. For configuring cloudwatch agent go to the below location using command prompt  

C:\Program Files\Amazon\AmazonCloudWatchAgent>amazon-cloudwatch-agent-config-wizard.exe

Then, configure the cloudwatch agent using Amazon CloudWatch Agent Configuration Manager as per the requirements or by referring the below link


  1. Modify the CloudWatch agent configuration file and specify the metrics that you want to collect by downloading the sample AWS.EC2.Windows.CloudWatch.json file. by using the below link.


  1. After configuring the metrics that you wanted, copy the sample AWS.EC2.Windows.CloudWatch.json file on your Windows Server at this location. 

            C:\Program Files\Amazon\SSM\Plugins\awsCloudWatch\

  1. Now, restart AmazonSSMAgent

            Run PowerShell as administrator and run this command –

            Restart-Service AmazonSSMAgent

These are custom metrics for Server’s Free disk space in GB and RAM available in MB: