Need help?

Our experts have had an average response time of 12.14 minutes in September 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Push custom metrics to CloudWatch

by | Jul 22, 2021

Wondering how to push custom metrics to CloudWatch? We can help you.

Here at Bobcares, we have seen several such AWS-related queries as part of our AWS Support Services for AWS users, and online service providers.

Today, we shall see how to push custom metrics to CloudWatch.


How to push custom metrics to CloudWatch?

AWS services push data points to CloudWatch by default.

However, there are instances where you must calibrate the performance of your resources based on metrics that aren’t supported by AWS services.

In these cases, you can push custom metrics to CloudWatch using the unified CloudWatch agent or the API.

Today, let us see the methods followed by our Support Techs to push custom metrics.

Push custom metrics using the CloudWatch agent

The unified CloudWatch agent collects system-level metrics and sends them to CloudWatch as custom metrics.

You can use the agent to push custom metrics from:

  • Linux or Windows servers
  • Amazon Elastic Compute Cloud (Amazon EC2) instances or on-premises servers

For Linux, refer to the list of supported metrics.

Sample agent configuration file metric block for disk metrics (Linux):

"measurement": [

"resources": [


For Windows, you can reference any counter mentioned in the Windows Performance Monitor in the agent configuration file.

Sample agent configuration file metric block for Processor Counter (Windows):

"Processor": {
"measurement": [
{"name": "% Idle Time", "rename": "CPU_IDLE", "unit": "Percent"},
"% Interrupt Time",
"% User Time",
"% Processor Time"
"resources": [
"append_dimensions": {
"d1": "win_foo",
"d2": "win_bar"

You can also use “StatsD” and “collectd” protocols to retrieve custom metrics from your applications or services.

Then, the metrics are push through the agent. StatsD is supported on both Linux and Windows servers.

Collectd is supported only on Linux servers. To use these protocols:

1. Firstly, install the CloudWatch unified agent.

2. Then, assign a role or credentials to the instance with CloudWatch permissions.

3. Next, create the CloudWatch agent configuration file.

4. Finally, start the agent.


Push custom metrics using PutMetricData

If your use case doesn’t support the use of the CloudWatch unified agent, you can use the PutMetricData API to push custom metrics to CloudWatch.

For example, to push connections for a specific port as a custom metric, you can retrieve the values locally and transfer them in the API:

total_conn=$(netstat -an | grep <port> | wc -l)
aws cloudwatch put-metric-data --namespace "totalconn" --metric-name <port> --dimensions Instance=<InstanceId> --value $ total_conn

Same way, you can use AWS SDKs to use the PutMetricData API and send custom metrics to CloudWatch.

Create a local script that runs periodically to send custom metrics.

The API is optimal for pushing different metrics and multiple values for the following reasons:

  • Firstly, you can use up to twenty different metrics in a single API.
  • Using the Values and Counts method, you can publish up to 150 values per metric with one PutMetricData request.
  • Next, you can use up to ten dimensions per metric.
  • Each PutMetricData request is limit to 40 KB for HTTP POST requests.

For example, instead of making a separate API call for each metric, you can push multiple metrics using a single API call:

aws cloudwatch put-metric-data --namespace "Usage Metrics" --metric-data file://metric.json

where metric.json is:

"MetricName": "DiskMetric",
"Value": <value_derived_by_some_calculation>,
"Unit": "Count"
"MetricName": "MemoryMetric",

"Value": <value_derived_by_some_calculation>,
"Unit": "Count"

[Still, stuck with the query? – We are here to help you.]


In short, today we saw how our Support Techs push custom metrics to CloudWatch.


Get 24x7 monitoring for your AWS servers

There are proven ways to get even more out of your AWS Infrastructure! Let us help you.

Spend your time in growing business and we will take care of AWS Infrastructure for you.


var google_conversion_label = "owonCMyG5nEQ0aD71QM";


Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.