Replace absent values with zeros

50 views
Skip to first unread message

Albert Aleksandrov

unread,
May 2, 2020, 6:26:12 AM5/2/20
to Prometheus Users
Hi all!
I have some areas with absent values like this:

Заявление.jpg


How can I replace them with zeros?
P.S. I tried query I learn from a course (you can see it on the screenshot) but it didn't work.

Brian Candler

unread,
May 2, 2020, 9:19:36 AM5/2/20
to Prometheus Users
Show individually the results of querying (in the prometheus console, non-graphical view)

health_check{job="platform-events-db", cluster="loco-prod"}

up{job="platform-events-db", cluster="loco-prod"}

Do they have exactly the same label sets? If not, you'll have to add on(...) or ignoring(...), or use group_left.

Also note: the query you have shown will only "fill in the gaps" for health_check if the scrape failed entirely, i.e. when up == 0.  If "up" was 1, but health_check was missing, it won't fill in the gap.  If that's the case, you could try:

health_check{...} or up{...} * 0

Final note: I would be *very wary* about doing this sort of data manipulation.  There is a critical difference between a health check failing, and a health check not running at all (or its result being lost).  If you confuse these two things, people may draw the wrong conclusions from the data.

Łukasz Mierzwa

unread,
May 2, 2020, 10:43:58 AM5/2/20
to Prometheus Users
You could also just tell grafana to render null values as zeros. There's a "Null value" select on the visualisation tab:

Screen Shot 2020-05-02 at 15.41.45.png

Julien Pivotto

unread,
May 2, 2020, 4:44:28 PM5/2/20
to Brian Candler, Prometheus Users
I agree that this can be done at grafana level -- null as zero.

In PromQL, that would be:

health_check or 0*count_over_time(health_check[30m])

>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/58f2a1d9-1970-43cb-b8ab-84ae072c12cc%40googlegroups.com.


--
(o- Julien Pivotto
//\ Open-Source Consultant
V_/_ Inuits - https://www.inuits.eu
signature.asc

Albert Aleksandrov

unread,
May 4, 2020, 12:00:01 PM5/4/20
to Prometheus Users
Thank you for your answer and cautions

суббота, 2 мая 2020 г., 16:19:36 UTC+3 пользователь Brian Candler написал:

Albert Aleksandrov

unread,
May 4, 2020, 12:00:55 PM5/4/20
to Prometheus Users
Thank you for this tip

суббота, 2 мая 2020 г., 17:43:58 UTC+3 пользователь Łukasz Mierzwa написал:
Reply all
Reply to author
Forward
0 new messages