1 # other rules to consider:
2 # filesystem, network, ntp rules:
3 # https://github.com/cloudalchemy/ansible-prometheus defaults/main.yml
4 # on my system, the interpolated values are in /a/opt/ansible-prometheus/rules.yml
12 ## uncomment for testing an alert firing
13 # - alert: test-alert4
15 # # expr: nonexistent_metric
20 # description: "always-firing alert VALUE = {{ $value }}"
24 ###### BEGIN MISC NOTES ######
27 # other interesting exporters
28 # https://github.com/prometheus-community/node-exporter-textfile-collector-scripts
31 # interesting post: https://www.metricfire.com/blog/top-5-prometheus-alertmanager-gotchas/
33 # interesting promql query that could be useful later.
34 # changes(ALERTS_FOR_STATE[24h])
38 # alert flap strategy.
39 # https://roidelapluie.be/blog/2019/02/21/prometheus-last/
41 # Another idea generally is to make an alert that fires for 24 hours and
42 # inhibits another alert for the same thing, which we want at most
43 # 1 alert per 24 hours.
45 ###### END MISC NOTES ######
47 # various queries only look at increases, so invert the up metric so we
48 # can better query on down.
53 # alerting on missing metrics:
54 # https://www.robustperception.io/absent-alerting-for-scraped-metrics
55 # that doesnt work if we want to alert across multiple hosts, eg
56 # up{job="node"} == 1 unless node_systemd_unit_state{name="systemstatus.service",state="active",job="node"}
57 # however, google lead me to a solution here
58 # https://www.linkedin.com/pulse/prometheus-alert-missing-metrics-labels-nirav-shah
59 # there is also the absent() function, but i didnt see a way to make that work
60 - alert: mysers_units_missing
62 count(up{job="node"} == 1) by (instance) * 3 unless
63 count(node_systemd_unit_state{name=~"(systemstatus|btrfsmaintstop|dynamicipupdate).service",state="active"}) by (instance)
68 - alert: epanicclean_not_active
70 node_systemd_unit_state{name="epanicclean.service",state="active"} != 1
75 - alert: epanicclean_missing
77 count(up{job=~"node|tlsnode"} == 1) by (instance) unless
78 count(node_systemd_unit_state{job=~"node|tlsnode",name="epanicclean.service",state="active"}) by (instance)
83 - alert: mysers_not_active
85 node_systemd_unit_state{name=~"(systemstatus|btrfsmaintstop|dynamicipupdate).service",state="active"} != 1
90 - alert: sysd_result_fail
91 # not sure 30m is really needed, it prevents the alert from flapping
94 rate(node_systemd_unit_result_fail_count[30m]) > 0
98 - alert: exim_paniclog
104 - alert: check_crypttab
110 - alert: mailtest_check_vps
112 time() - mailtest_check_last_usec{job="tlsnode"} >= 60 * 12
116 summary: '12 minutes down'
118 - alert: mailtest_check_unexpected_spamd_vps
120 mailtest_check_unexpected_spamd_results >= 1
124 summary: 'jr -u mailtest-check -e'
126 - alert: mailtest_check_mailhost
128 time() - max by (folder,from) (mailtest_check_last_usec{job="node"}) >= 60 * 12
132 summary: '12 minutes down'
134 # 20 minutes. just allow for more due to prod alert.
135 - alert: mailtest_check_gnu_mailhost
137 time() - max by (folder,from) (mailtest_check_last_usec{folder="/m/md/l/testignore", from="iank@gnu.org"}) >= 60 * 20
141 summary: '20 minutes down'
145 expr: hour() == 17 and minute() < 5
150 summary: Prometheus daily test alert
153 #### Inhibit notes ####
154 ## Example of expressions to detect if the target_down alert
155 # fired in the last 24 hours. Initially, I thought his could
156 # be an alert which inhibits up_resets, but eventually I figured
157 # that doesn't make much sense, and the idea of using an alert
158 # that is not an indication of something wrong, only inhibits another
159 # alert, I think works better to integrate directly into the
160 # alert it would inhibit, this may mean a recording rule. That avoids
161 # an alert we have to ignore or filter out.
163 # Alternate expression, to calculate if the alert would have fired is:
164 # min_over_time(sum_over_time(up[30m])[1d:]) == 0
165 # where 30m matches the for: time in target_down
167 # Note: for graphing, surround in the expression in sum_over_time()
168 # ALERTS{alertname="target_down",alertstate="firing"}[1d]
169 #### end Inhibit notes ####
172 # For targets where we alert only on long downtimes, we
173 # still want to know if it is going down many times for short times over
174 # a long period of time. But ignore reboots.
176 ## Another way would be to detect an overall downtime:
177 # avg_over_time(node_systemd_unit_state{name="dynamicipupdate.service",state="active"}[1d]) < .95
180 resets(up[1d]) - changes(node_boot_time_seconds[1d]) > 12
184 summary: "Target has gone down {{ $value }} times in 1 day, > 12"
188 # https://awesome-prometheus-alerts.grep.to/rules
190 # todo, we should probably group the prometheus alerts that indicate a
191 # host-local problem.
192 # eg, set a label alert-group: local-prom, then make a receiver that
193 # groups by it when the alert-group is local-prom.
195 - name: awesome prometheus alerts
198 - alert: PrometheusJobMissing
199 expr: absent(up{job="prometheus"})
204 summary: Prometheus job missing (instance {{ $labels.instance }})
205 description: "A Prometheus job has disappeared\n VALUE = {{ $value }}"
207 # TODO: some hosts, notably li and MAIL_HOST, we want to alert sooner than 30m,
208 # and severity to day. mail host is tricky since it roams, but I think the
209 # right way to do it is to check for absence of this metric:
210 # mailtest_check_last_usec{folder="/m/md/l/testignore",from="ian@iankelling.org"}
217 summary: Target down for 30m
220 # todo: this should group with the above alert
221 - alert: PrometheusAllTargetsMissing
222 expr: count by (job) (up) == 0
226 # alert-group: local-prom
228 description: "A Prometheus job does not have living target anymore.\n VALUE = {{ $value }}"
230 - alert: PrometheusConfigurationReloadFailure
231 expr: prometheus_config_last_reload_successful != 1
236 description: "Prometheus configuration reload error\n VALUE = {{ $value }}"
238 - alert: PrometheusTooManyRestarts
239 expr: changes(process_start_time_seconds{job=~"prometheus|pushgateway|alertmanager"}[30m]) > 10
244 description: "Prometheus has restarted more than ten times in the last 30 minutes. It might be crashlooping.\n VALUE = {{ $value }}"
246 - alert: PrometheusAlertmanagerJobMissing
247 expr: absent(up{job="alertmanager"})
252 description: "A Prometheus AlertManager job has disappeared\n VALUE = {{ $value }}"
254 - alert: PrometheusAlertmanagerConfigurationReloadFailure
255 expr: alertmanager_config_last_reload_successful != 1
260 description: "AlertManager configuration reload error\n VALUE = {{ $value }}"
262 - alert: PrometheusNotConnectedToAlertmanager
263 expr: prometheus_notifications_alertmanagers_discovered < 1
268 description: "Prometheus cannot connect the alertmanager\n VALUE = {{ $value }}"
270 - alert: PrometheusRuleEvaluationFailures
271 expr: increase(prometheus_rule_evaluation_failures_total[3m]) > 0
276 description: "Prometheus encountered {{ $value }} rule evaluation failures, leading to potentially ignored alerts.\n VALUE = {{ $value }}"
278 - alert: PrometheusTemplateTextExpansionFailures
279 expr: increase(prometheus_template_text_expansion_failures_total[3m]) > 0
284 description: "Prometheus encountered {{ $value }} template text expansion failures\n VALUE = {{ $value }}"
286 - alert: PrometheusRuleEvaluationSlow
287 expr: prometheus_rule_group_last_duration_seconds > prometheus_rule_group_interval_seconds
292 description: "Prometheus rule evaluation took more time than the scheduled interval. It indicates a slower storage backend access or too complex query.\n VALUE = {{ $value }}"
294 - alert: PrometheusNotificationsBacklog
295 expr: min_over_time(prometheus_notifications_queue_length[30m]) > 0
300 description: "The Prometheus notification queue has not been empty for 10 minutes\n VALUE = {{ $value }}"
302 - alert: PrometheusAlertmanagerNotificationFailing
303 expr: rate(alertmanager_notifications_failed_total[1m]) > 0
308 description: "Alertmanager is failing sending notifications\n VALUE = {{ $value }}"
310 # file_sd doesnt count as service discovery, so 0 is expected.
311 # - alert: PrometheusTargetEmpty
312 # expr: prometheus_sd_discovered_targets == 0
317 # description: "Prometheus has no target in service discovery\n VALUE = {{ $value }}"
319 - alert: PrometheusTargetScrapingSlow
320 expr: prometheus_target_interval_length_seconds{quantile="0.9"} > 90
325 description: "Prometheus is scraping exporters slowly\n VALUE = {{ $value }}"
327 - alert: PrometheusLargeScrape
328 expr: increase(prometheus_target_scrapes_exceeded_sample_limit_total[10m]) > 10
333 description: "Prometheus has many scrapes that exceed the sample limit\n VALUE = {{ $value }}"
335 - alert: PrometheusTargetScrapeDuplicate
336 expr: increase(prometheus_target_scrapes_sample_duplicate_timestamp_total[5m]) > 0
341 description: "Prometheus has many samples rejected due to duplicate timestamps but different values\n VALUE = {{ $value }}"
343 - alert: PrometheusTsdbCheckpointCreationFailures
344 expr: increase(prometheus_tsdb_checkpoint_creations_failed_total[1m]) > 0
349 description: "Prometheus encountered {{ $value }} checkpoint creation failures\n VALUE = {{ $value }}"
351 - alert: PrometheusTsdbCheckpointDeletionFailures
352 expr: increase(prometheus_tsdb_checkpoint_deletions_failed_total[1m]) > 0
357 description: "Prometheus encountered {{ $value }} checkpoint deletion failures\n VALUE = {{ $value }}"
359 - alert: PrometheusTsdbCompactionsFailed
360 expr: increase(prometheus_tsdb_compactions_failed_total[1m]) > 0
365 description: "Prometheus encountered {{ $value }} TSDB compactions failures\n VALUE = {{ $value }}"
367 - alert: PrometheusTsdbHeadTruncationsFailed
368 expr: increase(prometheus_tsdb_head_truncations_failed_total[1m]) > 0
373 description: "Prometheus encountered {{ $value }} TSDB head truncation failures\n VALUE = {{ $value }}"
375 - alert: PrometheusTsdbReloadFailures
376 expr: increase(prometheus_tsdb_reloads_failures_total[1m]) > 0
381 description: "Prometheus encountered {{ $value }} TSDB reload failures\n VALUE = {{ $value }}"
383 - alert: PrometheusTsdbWalCorruptions
384 expr: increase(prometheus_tsdb_wal_corruptions_total[1m]) > 0
389 description: "Prometheus encountered {{ $value }} TSDB WAL corruptions\n VALUE = {{ $value }}"
391 - alert: PrometheusTsdbWalTruncationsFailed
392 expr: increase(prometheus_tsdb_wal_truncations_failed_total[1m]) > 0
397 description: "Prometheus encountered {{ $value }} TSDB WAL truncation failures\n VALUE = {{ $value }}"