14
votes

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.

1

1 Answers

35
votes

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