Your applications can publish custom metrics to CloudWatch by using the AWS SDK. But if yours is a simple use case & all you need is a quick & easy way to get a few custom metrics to CloudWatch, you can use CloudWatch Logs metric filters to generate custom metrics from the logs you push to CloudWatch.
Consider a scenario where your application logs “Order processed successfully.” to CloudWatch. If you just need to count the number of orders processed successfully, wouldn’t it be easier to count for this line in the logs, than to write code using AWS SDK to publish custom metrics? That’s what a metric filter does.
Start by opening the log groups list at https://console.aws.amazon.com/cloudwatch/home#logsV2:log-groups. Click on a log group to open it. Scroll down & select the metric filters tab & click create metric filter:
Now whenever an order is processed successfully, the custom metric
my-app/orders-processed-successfully‘s value goes up by 1.