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 can divide the Errors metric by the Invocations metric to get an error rate. You can then add the resulting time series to a graph on your CloudWatch dashboard.

Read all about Math expressions here.

  1. In the AWS Management Console on the Services menu, click CloudWatch.
  2. In the left navigation menu, click on Metrics.
  3. Click on the namespace called ContainerInsights.
  4. Select the ClusterName, Namespace, PodName dimension.
  5. Copy the following text and enter it into the search bar:
ClusterName="PetSite" Namespace="kube-system" MetricName="pod_cpu_utilization"
  1. Check all the checkboxes next to the returned metrics to display them on the graph.

Your screen should look similar to the screenshot shown below.


As shown above, the graph shows the pod_cpu_utilization metric from the different pods that are all part of the Kubernetes data plane.

  1. Click on the Graphed metrics tab.
  2. Click math expression, then All functions, followed by SUM.

This allows you to use a Metric Math expression to sum all the metrics and show them as a single line on the graph.

See the GIF below for clarification.


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.



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 Math expression and check out the various functions available.


This concludes this section. You may continue on to the next section.