'Prometheus - exclude 0 values from query result

I'm displaying Prometheus query on a Grafana table. That's the query (Counter metric):

sum(increase(check_fail{app="monitor"}[20m])) by (reason)

The result is a table of failure reason and its count.
The problem is that the table is also showing reasons that happened 0 times in the time frame and I don't want to display them.
AFAIK it's not possible to hide them through Grafana.

I know prometheus has comparison operators but I wasn't able to apply them.



Solution 1:[1]

I don't know how you tried to apply the comparison operators, but if I use this very similar query:

sum(increase(up[1d])) by (job)

I get a result of zero for all jobs that have not restarted over the past day and a non-zero result for jobs that have had instances restart.

If I now tack on a != 0 to the end of it, all zero values are filtered out:

sum(increase(up[1d])) by (job) != 0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alin Sînp?lean