25

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.

nirsky
  • 2,955
  • 3
  • 22
  • 35

1 Answers1

56

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
Alin Sînpălean
  • 8,774
  • 1
  • 25
  • 29
  • 1
    Simple succinct answer. I've been using comparison operators in Grafana for a long while. Stumbled onto this post for something else unrelated, just was +1-ing this :) – Farley Jul 28 '20 at 00:33
  • Simple, clear and working - thanks a lot. It's worth to add that if using Grafana you should set 'Connect null values' proeprty to 'always' in order to get rid of blank spaces in the graph. – nuclear_party Oct 21 '22 at 19:27