How to ignore empty dataseries in prometheus
Asked Answered
S

1

11

Calculating the maximum quantile over all dataseries is a problem for me:

query

http_response_time{job=~"^(x|y)$", quantile="0.95",...}

result

http_response_time{job="x",...} 0.26
http_response_time{job="y",...} NaN

This is how I would try to calculate the maximum:

avg(http_response_time{job=~"^(x|y)$",...})

Now the result will be "NaN". How can I ignore the "NaN" result (from the result section)?

UPDATE 0

The metric is a self made summary-metric.

UPDATE 1

Using prometheus version 1.8.

Stefanistefania answered 19/12, 2017 at 12:32 Comment(2)
Can you share more information about the metric in question, and where it's coming from?Crammer
http_response_time{job="x",...} 0.26 http_response_time{job="y",...} NaN returned by http your node_exporter?Wentworth
R
25

I didn't try this one with NaN, but you can simply filter by values with binary operators. Since NaN mathematically doesn't equal NaN you could try this trick (since a response time should be always positive):

avg(http_response_time{job=~"^(x|y)$",...} >= 0)
Rayshell answered 19/12, 2017 at 13:11 Comment(3)
Good try. But "http_response_time{ quantile="0.95"} != NaN" does not filter/remove the "NaN" results.Stefanistefania
Looks good. Will check it in detail before setting your answer as "correct". THX!Stefanistefania
By definition, NaN boolean operations are strange. For example "NaN != NaN" returns true in Javascript and pretty much every other language.Cheek

© 2022 - 2024 — McMap. All rights reserved.