> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Publishing Custom Metrics

> Guide showing how to publish and verify custom application metrics to Amazon CloudWatch using the AWS CLI, including flags, best practices, and verification steps.

Welcome. In this lesson you'll learn how to publish custom metrics to Amazon CloudWatch. CloudWatch exposes many built-in metrics for AWS services, but application-specific measurements (for example, the number of orders processed) require publishing custom metrics. We’ll use CloudShell (or any AWS CLI–enabled environment) to send a metric and then verify it in the CloudWatch console.

Prerequisites

* An AWS account with permissions to call CloudWatch `PutMetricData`.
* The AWS CLI configured in CloudShell or your local terminal: [https://aws.amazon.com/cli/](https://aws.amazon.com/cli/)
* Optional: access to the CloudWatch console: [https://console.aws.amazon.com/cloudwatch/home](https://console.aws.amazon.com/cloudwatch/home)

Step 1 — Prepare your terminal
Clear your terminal and compose the AWS CLI command to publish metric data. The API operation is `put-metric-data` (see the PutMetricData API docs: [https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API\_PutMetricData.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricData.html)). You must specify a namespace, metric name, value, and (optionally) a unit and dimensions.

Example command:

```bash theme={null}
aws cloudwatch put-metric-data \
  --namespace MyApplication \
  --metric-name OrdersProcessed \
  --value 25 \
  --unit Count
```

Sample terminal interaction:

```bash theme={null}
Preparing your terminal...
~ $ aws cloudwatch put-metric-data --namespace MyApplication --metric-name OrdersProcessed --value 25 --unit Count
~ $
```

CLI flags reference

| Flag | Required | Description | Example |
| - | - | - | - |
| `--namespace` | Yes | Logical grouping for metrics. Use a descriptive name like your application or team. | `MyApplication` |
| `--metric-name` | Yes | The metric name (case-sensitive). | `OrdersProcessed` |
| `--value` | Yes | Numeric measurement to publish. | `25` |
| `--unit` | No | Measurement unit (recommended). Must be one of CloudWatch units (Count, Seconds, Bytes, etc.). | `Count` |
| `--dimensions` | No | Key/value pairs to filter/aggregate metrics. Use CLI syntax: `Name=Key,Value=Value`. | `Name=Service,Value=Checkout` |
| `--storage-resolution` | No | `1` for high-resolution (1s) metrics; default is `60` seconds. | `1` |

Notes about best practices and important behaviors

* `--namespace` groups related metrics together. Choose consistent, descriptive namespaces (e.g., your application name or team).
* Metric names and namespaces are case-sensitive.
* Attach `--dimensions` such as `Name=environment,Value=prod` or `Name=service,Value=checkout` to enable finer-grained filtering and aggregation.
* Use `--storage-resolution 1` to publish high-resolution (1-second) metrics when you need sub-minute granularity.
* Units are optional but recommended to make metrics easier to interpret and to avoid unit-mismatch issues when creating alarms.

Verification — Check CloudWatch console
Give CloudWatch a few seconds (typically under a minute) to ingest the data. Then open the CloudWatch console and navigate to Metrics → All metrics. You should see your custom namespace (for example, `MyApplication`) and the metric `OrdersProcessed` within it. If you didn’t publish dimensions, the metric will appear without them.

![A screenshot of the AWS CloudWatch Metrics console showing an empty "Untitled graph" and time-range controls. Below the graph is a metric list that includes "OrdersProcessed" with no alarms.](https://mintcdn.com/kodekloud-c4ac6d9a/SSy1aL2mVSdeEi1p/images/AWS-Certified-DevOps-Engineer-Professional/Domain-4-Monitoring-and-Logging/Demo-Publishing-Custom-Metrics/aws-cloudwatch-empty-untitled-graph-ordersprocessed.jpg?fit=max\&auto=format\&n=SSy1aL2mVSdeEi1p\&q=85\&s=2a188114dfc9b34d7e31b6e021d0464d)

Best practices: Use consistent namespaces and metric names. Attach dimensions (for example, `environment=prod`, `service=checkout`) to enable finer-grained filtering, aggregation, and alarm targeting.

What you can do next

* Add the metric to dashboards for continuous visibility.
* Create CloudWatch alarms on thresholds, anomalies, or rate-of-change.
* Aggregate metrics by dimension, statistic (Sum, Average), and period to drive alerts and automated remediation.

References

* PutMetricData API: [https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API\_PutMetricData.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricData.html)
* AWS CloudShell: [https://aws.amazon.com/cloudshell/](https://aws.amazon.com/cloudshell/)
* AWS CLI: [https://aws.amazon.com/cli/](https://aws.amazon.com/cli/)
* CloudWatch metrics and units: [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch\_concepts.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html)

This is how you publish and verify a custom metric in CloudWatch when built-in AWS metrics don’t cover your application’s needs.

> **[Watch Video](https://learn.kodekloud.com/user/courses/aws-certified-devops-engineer-professional/module/15ed9473-60f4-466a-b7b2-3d9cb829e847/lesson/01022b99-ae9d-4459-af5b-db498d308cef)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.