Time series: how to set nulls as zero?
Fill No Data with 0 for calculations
Add fill(0) and fill(null) option to InfluxDB query editor
Fill missing values with zero
Hello everyone,
I hope you can help me with this situation.
I have a time-series graph on my grafana.
If I have the Connect Null Values set as Always it appears this way:
If I set to Never it appears this way:
Is there a way to make the line continue on 0 instead of this breaks when the Never option is set or the connecting line that doesn’t show the correct value when the Always option is set?
The data comes from Elasticsearch and in some timestamps there are no results, so I need the line to stay continuous at 0.
Here is the current config I have:
None of this configs work :(
Could you help me solving this?
Thank you so much!
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)
The following technique can be used for filling gaps in a single time series returned from the query q:
sum(q) or vector(0)
The q is wrapped into sum() in order to drop all the labels for a time series returned from q, so the time series can be matched with vector(0) time series according to matching rules for or operator. The query without sum(): q or on() vector(0) would return two time series on the graph instead of a single time series: one time series from q with its own set of labels and another time series with zero labels and with zero value where the q time series contains gaps.
Unfortunately Prometheus doesn't provide an easy ability to fill gaps with zeroes if q returns multiple time series with distinct labelsets. Other Prometheus-like solutions such as VictoriaMetrics (I work on it) provides default operator for this case. For example, the following MetricsQL query fills gaps with zeroes for all the time series returned from q:
q default 0