Search code examples
amazon-cloudwatch

AWS Cloudwatch Math Expressions: draw null / empty


I am trying to create a dashboard widget that says "if a metric sample count is less than certain number, don't draw the graph".

The only Math expression that seem promising is IF, however the value can only be a metric or a scalar. I'm trying to find a way to draw a null/no data point/empty instead.

Any way?

Reference: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html#using-IF-expressions


Solution

  • CloudWatch will drop data points that are not numbers (NaN, +Infinity, -Infinity) when graphing the data. Also, metric math will evaluate basic operations in the expression. You can divide by zero to get non-number value.

    So you can do something like this to trick it into dropping the values you don't want:

    • Have your metric in the graph as m1.
    • Have the sample count of your metric in the graph as m2.
    • Add an IF function to drop data points if the sample count is lower than some number (10 in this example): IF(m2 < 10, 1/0, m1)
    • Disable m1 and m2 on the graph and only show the expression.