Time series: how to set nulls as zero?

  • What Grafana version and what operating system are you using?
    Docker Grafana 8.1.5

  • What are you trying to achieve?
    Plot a Prometheus Counter with various labels as a time series, and fill all null/missing values as zeros.

  • How are you trying to achieve it?
    Using time series graph.

  • What happened?
    The graph display works, but the new time series graph is missing an option that the Graph (old) has under Display > Stacking and null value > null value: null as zero, hence we now end up with broken lines for null values.

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

  • What did you expect to happen?
    I was expecting an option to fill nulls as zeros in the time series.

  • Can you copy/paste the configuration(s) that you are having problems with?
    This is the query applied to the counter:
    my_metric{code!=""}

Again, this is a Prometheus COUNTER with various labels that all get displayed in the graph.

if I add “or on() vector(0)” to the end of the query, the condition (and therefore the value) does not get applied to the data series for each individual label…

Thanks for any suggestions !

2 Likes

@peter83
have you explored using the new field overrides section in Grafana 8? There is an option in there for connect null values. does that fix your broken lines?

HI Matt, yes the option under Graph styles > Connect null values > ALWAYS is enabled, it does not change anything. null/or missing values are NOT filled as zeros.

How can I do that in the new Timeseries graph ?

1 Like

So this is not currently possible in the new time series panel. I would start a discussion around this, as I know others feel it is a regression and should return:

any luck with this? Even latest grafana I am seeing few panels which don’t work well with all nulls. I am using hex panel and it freaks out when it deals with all null series.

The same panel works just fine when there is some data. So going back to original ask on How do we set result to 0 when input is null series? Can that be an option in Transform section?

You can convert to numeric to force nulls as 0 (via transforms):

1 Like

Hi. I have older Graphs with 5 metrics with gaps for nulls (broken lines as the topic starter mentioned). I tried using all the options for Null value: “connected”, “null” and “null as zero”, tried forcing transform to numeric for all my metrics as skwasjer suggested and tried switching to newer Time Series graphs and doing all this there + all line interpolation options and mapping “null” to “0”, but nothing changes, I still get broken lines. So I assume this is a bug in Grafana, and I’d appreciate a workaround for this.

as in you are using the graph (old) panel?

I am, but I also tried the new Time Series, and it didn’t work either