Getting Negative Values when calculating from two timestamps like (value at 1hr before - value at 2hr before from now)

Getting Negative Values when calculating from two timestamps like (value at 1hr before - value at 2hr before from now)

Usually for low data and counter the result is proper and accurate but for greater values and counters it gives negative values which is wrong.
kindly suggest how to tackle it.
below is my query:

((haproxy_backend_http_responses_total{proxy!="(stats)",code=~"(5xx|4xx|3xx|1xx)",job = “haproxy”,instance=~"$host:$port"} offset 1m) - (haproxy_backend_http_responses_total{proxy!="(stats)",code=~"(5xx|4xx|3xx|1xx)",job = “haproxy”,instance=~"$host:$port"} offset 2m))

@grafana experts please express your understanding on my concern.

Hi @abhisheksingh3,

Can you share a few screenshots please? Are you using the HA Proxy Exporter for Prometheus? Can you provide some examples of your data, like an example where the values are correct and where they are not?

1 Like


Yes sir, using HA proxy exporter.

Value is correct for other server having less HAproxy requests/responses.
refer below snap:

Please help me out.

Hello Matt,

did you get time to check where i am going wrong…

Hello Team,
Please help me out.

Regards,
Abhishek Singh

Hi @abhisheksingh3,

Have you noticed the warning in the bottom of your screenshot? The one about trying to apply a rate function?

I would also check out the examples on play.grafana.org. You will find a look of excellent Prometheus queries on that playground/sandbox site. I would try adapting one of their queries and see where that gets you.

Let me know how it goes!

~matt