Math expressions

Metric math enables you to query multiple CloudWatch metrics and use math expressions to create new time series based on these metrics. You can visualize the resulting time series on the CloudWatch console and add them to dashboards. Using AWS Lambda metrics as an example, you could divide the Errors metric by the Invocations metric to get an error rate. Then add the resulting time series to a graph on your CloudWatch dashboard.

Now Click here to see all the metrics under ClusterName, Namespace, PodName dimension under the ContainerInsights namespace on CloudWatch Metrics. Apply filters as shown below and graph all metrics.

Metrics8

As seen above, the graph shows pod_cpu_utilization metric from 3 different pods that are all part of the Kubernetes data plane. Now, simply using a Metric Math expression, we can sum all the metrics and show them as a single line graph.

See the GIF below on how you can do this.

Metrics9

Doing this creates a new expression which uses the Metric Match function called SUM(). When you supply METRICS() as an argument to the SUM() expression, it aggregates all the metrics that are graphed except the ones that are math expressions.

You can also achieve the same result without using the METRICS() function as shown below, where m1,m2 and m3 being the metric Ids.

SUM([m1,m2,m3])

Metrics10

Notice that you can also create CloudWatch Alarms based on Metric math expressions.

There are numerous such expressions available for you to operate on Metric data.

To see all expressions simply click on Metric expression and check out the various functions available.

Metrics11