How to populate CloudWatch metric with zeros?

  • What Grafana version and what operating system are you using?
    Grafana v10.4.2 (701c851be7) from Docker image “grafana/grafana-oss:10.4.2”

  • What are you trying to achieve?
    There are two metrics in CloudWatch: RequestCount and HTTPCode_ELB_5XX_Count. I want to graph a ratio of errors vs total requests for a given load balancer. I.e. (RequestCount - HTTPCode_ELB_5XX_Count) / RequestCount.

  • How are you trying to achieve it?
    I fetch RequestCount as A

Then I fetch HTTPCode_ELB_5XX_Count as B

Finally, I find the ratio

  • What happened?
    Unfortunately (what an irony) 5XX response are rare. If there are no 5xx responses, CloudWatch doesn’t include a zero value in the B time series. As a result, my final series C doesn’t have data points since the last non-zero 5xx value.
    Compare these three series plotted separately.
    A (RequestCount):

B (HTTPCode_ELB_5XX_Count)

C ( ($A - $B)/$A ):

  • What did you expect to happen?

Is there a way to maybe fill the HTTPCode_ELB_5XX_Count with zeroes so the ratio looks accurate?

  • Can you copy/paste the configuration(s) that you are having problems with?

Will be happy to provide any config, but given the simplicity of my graphs I feel like it will be redundant.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    There were no errors.

  • Did you follow any online instructions? If so, what is the URL?

2 Likes

It can be only visual problem, so try to not connect null values: Time series | Grafana documentation

Or use CloudWatch metric math and try +0. It may generate zeroes, because:

Missing values in a time series are treated as 0.

Hi Jan,

Thank you for your response.
Indeed, CloudWatch treats no data point as a zero. Even if I directly use the HTTPCode_ELB_5XX_Count metric in the ratio calculation, the result looks great.


result:
image

I’d like to produce the same graph in a Grafana dashboard.

Can the CloudWatch data source pull the calculated expression?
Or maybe a Grafana transformation can produce a series with zeros instead of “no data” points?

That “calculated expression” is CloudWatch metric math - that’s what I suggested already and that’s your e1:

Don’t use Grafana’s expressions, use exactly what you used in the CloudWatch console.

It sounds, the e1 series I’ve created in the CloudWatch UI is available in Grafana. If that’s the case, how can I access it?

I think you don’t understand.
You can write CloudWatch metric math in CloudWatch console - that “e1 series”.
You can write exactly the same CloudWatch metric math in Grafana queries - you have different UI, but it will be the same.

Please study this SLO - IMHO exactly your case, I don’t use generic m1,m2,e1 IDs, but more meaningful names in IDs:

Use doc to understand used CloudWatch metric math functions, operators, …, e.g. FILL:

Perfect. Exactly what I wanted to achieve. I really didn’t understand how to put it together.
I appreciate your time to explain this with a screenshot. Thank you!

1 Like

This helped me alot