Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time series from Prometheus source: how to set nulls as zero?

Working in Docker Grafana 8.1.5. Using time series graph, I'm plotting a Prometheus Counter source (that has one label) as a time series (by label), and need to fill all null/missing values as zeros.

This is the query applied to the Prometheus counter source, plotting the label code:

my_metric{code!=""}

The graph display works (just need to see the current counter value for each label variant, and the difference within the selected time range), but the new Grafana time series graph is missing an option that the Graph (old) has under Display > Stacking and null value > null value: null as zero, hence it now ends up with broken lines when null values occur.

Unfortunately, I cannot use the Graph (old) chart as I need the legend value difference, which only is available in the new time series graph.

I tried to add or on() vector(0) to the end of the query, but the condition does not get applied to the data series for each label variant, it rather adds a new data series all filled with zeros...

Thanks for any suggestions !

like image 373
pete19 Avatar asked Dec 22 '25 02:12

pete19


1 Answers

I had this issue as well and I was not able to use only or on() vector(0) as you mentioned because the main query was returning NaN. In my case I had a division by zero.

I could get around of it by first evaluate if the query has a value >= 0 and then use the or on() vector(0). Try something similar to:

((my_metric{code!=""}) >= 0) OR on() vector(0)
like image 83
Felipe Avatar answered Dec 24 '25 08:12

Felipe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!