Wrong Math results?

What Grafana version and what operating system are you using?

  • Version: Grafana v9.4.13 (e63c0e529c)
  • OS: probably centos

What are your issues?

  • I am trying to calculate and display percentage of failure using timeseries data and Gauge dashboard

  • I’m using Prometheus as datasource

  • It seems like addition and subtraction is works like a charm, but division and multiplication between summed values are giving out wrong answers.

  • for example,

     sum(..condition) + sum(..condition)
     sum(..condition) - sum(..condition)
     sum(..condition) / 10
     sum(..condition) * 10

    these calculation works fine but,

    sum(..condition) / sum(..condition)
    sum(..condition) * sum(..condition)

    this gives out some random numbers that I don’t even know how it’s calculated.

I want to know how can I get correct calculation for division and multiplication

How are you trying to achieve it?

I’ve tried following measures

0. My Dashboard Option

  • Datasource: Prometheus
  • Visualization: Gauge
  • Value options:
    • Show: calculate
    • Calculation: Total
    • Fields: Numeric Fields

1. Using Prometheus Query (PromQL)

 sum(delta(MESSAGE_STATUS_UPDATED_total{message_status="FAILED"}[1m])) / 

Obviously result should be 1, but it gives me 11 instead

Also, for same time range


gives me 83

sum(delta(MESSAGE_STATUS_UPDATED_total{message_status="FAILED"}[1m])) * sum(delta(MESSAGE_STATUS_UPDATED_total{message_status="FAILED"}[1m]))

but this gives me 684.

sum(delta(MESSAGE_STATUS_UPDATED_total{message_status="FAILED"}[1m])) * 83

funny thing is that this gives me correct answer which is 6889.

Thanks to chatGPT I’ve already tried changing some of the functions used in query by his help

  • using rate instead of delta → still not working
  • using increase instead of delta → still not working

2. Using expression

so I’ve separated query to use Expression instead. sorry for repeating queries but I want to show exactly what I did.

# Query A (result: 83)

# Query B (result: 83)

# Expression (result: 11)
Operation: Math
Expression: $A / $B

guess what the result was still 11

3. Using transform

well so I thought maybe it’s the problem of Prometheus, and tried to use transform to use Binary Operation

and this is the result

Now, I’m not sure what other ways I can try to get the correct division, multiplication response.
Do anyone know if there is a way to get correct division value?

Thanks in advance.

Pls show all panel config options

Hi, this is what all I have for panel config. Thank you

You think that A/B expression is simple. It isn’t, because you don’t consider time dimension:

A, B generates times series:

So also C is timeseries = list of 1 with different timestamps.

But Gauge panel doesn’t visualize time dimension, so you need from list of values, just one, which will be show G\auge panel:

You selected total (sum), so I guess C is just list of 11x1, which are summed and showed as 11 in Gauge panel.

1 Like

Thank you so much!
you were right, there were bunch of ones when I views data in table view.
I gotta figure out how to divide summed data now.

At least now I know where did the division calculation came from :joy:

Thank you!

1 Like

Just don’t use range queries, when you don’t need timeseries. Understand how instant queries work.

1 Like