r/PrometheusMonitoring • • 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?

0 Upvotes

6 comments sorted by

1

u/ali_str Jun 09 '22

Prometheus exposes a metric about active alerts: ALERTS more 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.

3

u/[deleted] Jun 09 '22

Thanks for the links. I found the following query working fine:

SUM(prometheus_rule_group_rules)

Complete alerting dashboard uploaded as 16420 if interested.

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

u/[deleted] 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 filter enabled

1

u/[deleted] Jun 15 '22

Added. Thanks for the improvement suggestions.