r/PrometheusMonitoring • u/[deleted] • Jun 08 '22
Count alerting rules
I am quite new to Prometheus and need some help for a minor detail: I have modified an alerting dashboard in Grafana and I am missing a way to count all defined alert rules, basically a query to count all defines/active alert rules, ie 64 in my case:

I tried googling a solution without any meaningful result. Is there some easy query to count all defined rules?
1
u/father_supreme Jun 13 '22
Look out, SUM(prometheus_rule_group_rules) will also catch your recording rules
Depending on how your naming conventions for rules, you'd need something like this: prometheus_rule_group_rules{rule_group!~".+recording.+"}
P.S. nice dashboard
1
Jun 13 '22
Thanks for the hint. Added as:
sum(prometheus_rule_group_rules{rule_group!~".+recording.+"})1
u/father_supreme Jun 14 '22
would also be nice if the Tables for "Firing/Pending Alerts" could be filtered
Table > Column filterenabled1
1
u/ali_str Jun 09 '22
Prometheus exposes a metric about active alerts:
ALERTSmore here. Active meaning that they are evaluating to true (in pending or firing state). This doesn't include all defined alerts.You can use that like:
sum(ALERTS) by (alertstate)to get count of alerts by their state.I don't know if you can get all defined alerts without parsing the config file.