Identifying AWS CloudWatch used metrics

Gonzalo E. Vásquez Sáez
2 min readAug 22, 2020

Today I realized we had an “outrageous” increment in CloudWatch costs in our bill and, by breaking it down I found out that `CW:MetricMonitorUsage` was the most relevant Usage Type, according to Cost Explorer. As I had already dug into cost analysis before, I realized that a simple Node.js script might help to identify the top offenders and, actually it was even nicer than that, as a single resource was accounted for +90% of the actual SampleCount statistics, which is what I used as criteria for cost allocation in this case, given that fore-mentioned Usage Type is what this actually accounts for.

Not 100% commented, but the working code is available at GitHub.

The resulting output from running the script will provide you (logged in the console) an unordered list of Metric Names with their corresponding Sample Count for the last 7 days, which you should order with the tool of your preference (or hopefully commit code changes and submit a PR) to point to your most-used metrics.

In our scenario top 4 metrics (93% of total) where ELB related and, when digging deeper through CloudWatch Console, there was just a single load balancer accounting for most of the metrics and, this balancer was actually NOT needed, as it’s an internal one which has only one registered target, so next steps are pretty easy to guess.

Top contributors

PS: Already committed to master the missing sort for the output, which was actually a one-liner using a lambda from StackOverflow.

--

--

Gonzalo E. Vásquez Sáez

Electronics Engineer, Degree in Computer Science with over 20 years of software development craftsmanship, last 5 years fond unofficial AWS evangelist.