- Newest
- Most votes
- Most comments
The issue you're encountering is related to how CloudWatch metric math handles operations on collections of metrics versus individual metrics. When you use METRICS() to create a collection and then apply DIFF() to it, you're working with a collection of time series data. The problem occurs when trying to perform arithmetic operations between collections and individual metrics or between different collections.
For your specific case, where you want to calculate the percentage difference between the current week and previous week, there isn't a direct way to apply the formula (DIFF(m1)/(m1-DIFF(m1)))*100 to a collection of metrics using METRICS().
Instead, you'll need to create individual expressions for each metric. While this might seem tedious, it's the most reliable approach given CloudWatch's metric math limitations.
If you're working with many metrics, consider:
- Using the CloudWatch API to programmatically create your dashboard with all the required expressions
- Creating a template dashboard with a few key metrics and duplicating the pattern as needed
- Using CloudWatch Metric Insights to query and filter your metrics before applying math expressions
The IF function might be useful in cases where you need to handle missing data points, as it can substitute values when certain conditions are met. For example:
IF(metric1, metric2, metric3)
This would use values from metric2 when metric1 is non-zero and non-missing, and values from metric3 otherwise.
Unfortunately, there's no direct shortcut to apply complex percentage calculations across a collection of metrics in a single expression. You'll need to create individual expressions for each metric you want to analyze.
Sources
Using math expressions with CloudWatch metrics - Amazon CloudWatch
Create a target tracking policy using high-resolution metrics for faster response - Amazon EC2 Auto Scaling
answered a year ago
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 5 months ago
