Trigger alert when x number of hosts are above value

I currently have a alert query based on Prometheus data. I first query that data,

scrape_samples_post_metric_relabeling{job!="prometheus"}

I then reduce the value to only look at the last value,

I then filter the values to only include hosts that contain a value that is greater than 7500

I now want to only trigger the alert if the number of hosts is greater than 5. Does anyone have any ideas on how to do this? Thanks!

Welcome @nschile to the Grafana forum.

Maybe add this?
image

and then alert off expression D?

image

It may require an adjustment somewhere. Remember to run the queries and the preview the alerts and see what shows up.

That worked. Thanks for the assistance.

Actually, the $C > 5 didn’t work. It appears that $C would only ever be 1 or 0. I need a way to determine how many hosts met criteria $C

OK, just winging it here, but maybe something like this…

Query A: scrape_samples_post_metric_relabeling{job!="prometheus"}
Expression B:


Expression C:

Alert off expression C

If you click Preview Alerts, you will be able to see the value in Expression B (i.e. the number of hosts that met criteria C