Sitemap

PromQL / How to return 0 instead of ‘no data’

Oct 14, 2019

Another short note. I found this answer in the middle of issue on Grafana GitHub and decided to make a memo.

So I wanted to show in ‘single stat’ panel number of alets. But when there is no alerts, my request returns no data , which is not informative.

And to solve this, you just need to add OR on() vector(0) to the end of your promQL query. It will return 0 if the metric expression does not return anything.

Explanation: Prometheus uses label matching in expressions. If your expression returns anything with labels, it won't match the time series generated by vector(0). In order to make this possible, it's necessary to tell Prometheus explicitly to not trying to match any labels by adding on().

--

--

Responses (6)