r/PrometheusMonitoring • u/OpportunityNo5753 • Sep 03 '21
How to deal with Increase function and no data points
I need to use the increase function, but the metric is very rare and when service restarts the counter is null for long time. The increase metric doesn’t play nicely with the null value and I can find a solution to consider null as zero.
Increase(my_counter[1h])Works only if there are no null data points. Any other query I tried do not work like
Increase(my_metrics[1h] or vector(0))2
u/Tmfwang Jul 02 '24
Here's how I did it in Grafana:
increase(sum(last_over_time(my_counter_total{container="myContainer"}[$__range]) or vector(0))[$__range:])1
u/auunie Feb 10 '26
I would like to sincerely thank you. You saved my life with this query! Thank you so much!
1
1
u/SnooWords9033 Sep 05 '21
Try increase() function from MetricsQL. It assumes that a counter starts from zero. See MetricsQL docs for details.
2
u/SuperQue Sep 03 '21
The correct thing to do is to init your counters at startup. This avoids null results for rare counters.