14d4275069de0f57b81c32a469a95814d844037b
[distro-setup] / filesystem / etc / prometheus / rules / iank.yml
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
5 #
6
7
8 groups:
9 - name: standard
10 rules:
11
12 # ## uncomment for testing an alert firing
13 # - alert: test-alert4
14 # expr: vector(1)
15 # for: 0m
16 # labels:
17 # severity: day
18 # annotations:
19 # description: "always-firing alert VALUE = {{ $value }}"
20
21
22
23 ###### BEGIN MISC NOTES ######
24
25 #
26 # other interesting exporters
27 # https://github.com/prometheus-community/node-exporter-textfile-collector-scripts
28 #
29
30 # interesting post: https://www.metricfire.com/blog/top-5-prometheus-alertmanager-gotchas/
31
32 # interesting promql query that could be useful later.
33 # changes(ALERTS_FOR_STATE[24h])
34 #
35 #
36 #
37 # alert flap strategy.
38 # https://roidelapluie.be/blog/2019/02/21/prometheus-last/
39 #
40 # Another idea generally is to make an alert that fires for 24 hours and
41 # inhibits another alert for the same thing, which we want at most
42 # 1 alert per 24 hours.
43
44 ###### END MISC NOTES ######
45
46
47 # various queries only look at increases, so invert the up metric so we
48 # can better query on down.
49 - record: down
50 expr: up == bool 0
51
52 # convenience metric to use in multiple alert expressions
53 - record: mailtest_lag_inhibit
54 expr: present_over_time(ALERTS{alertname=~"kd_eth0_down|target_down|cmc_wan_down"}[17m]) or on() count_over_time(up{job="prometheus"}[19m]) <= 18
55
56
57 # the node_network_info here goes away when it is down,
58 # https://www.robustperception.io/absent-alerting-for-scraped-metrics
59 #
60 # What this says is: return metric if up == 1 if there isnt also
61 # the right hand metric (with the same instance+job).
62 #
63 # aka:
64 # ! exists(operstate=up) && up
65 - alert: cmc_wan_down
66 expr: |-
67 up{instance="10.2.0.1:9100"} == 1 unless on(instance,job) node_network_info{instance="10.2.0.1:9100",device="wan",operstate="up"}
68 labels:
69 severity: day
70
71 - alert: kd_eth0_down
72 expr: |-
73 node_network_up{instance="kdwg:9101",device="eth0"} != 1
74 labels:
75 severity: day
76
77
78 # alerting on missing metrics:
79 # https://www.robustperception.io/absent-alerting-for-scraped-metrics
80 # that doesnt work if we want to alert across multiple hosts, eg
81 # up{job="node"} == 1 unless node_systemd_unit_state{name="systemstatus.service",state="active",job="node"}
82 # however, google lead me to a solution here
83 # https://www.linkedin.com/pulse/prometheus-alert-missing-metrics-labels-nirav-shah
84 # there is also the absent() function, but i didnt see a way to make that work
85 - alert: mysers_units_missing
86 expr: |-
87 count(up{job="node"} == 1) by (instance) * 3 unless
88 count(node_systemd_unit_state{name=~"(systemstatus|btrfsmaintstop|dynamicipupdate).service",state="active"}) by (instance)
89 for: 20m
90 labels:
91 severity: warn
92
93 - alert: epanicclean_not_active
94 expr: |-
95 node_systemd_unit_state{name="epanicclean.service",state="active"} != 1
96 for: 20m
97 labels:
98 severity: warn
99
100 - alert: epanicclean_missing
101 expr: |-
102 count(up{job=~"node|tlsnode"} == 1) by (instance) unless
103 count(node_systemd_unit_state{job=~"node|tlsnode",name="epanicclean.service",state="active"}) by (instance)
104 for: 20m
105 labels:
106 severity: warn
107
108 - alert: mysers_not_active
109 expr: |-
110 node_systemd_unit_state{name=~"(systemstatus|btrfsmaintstop|dynamicipupdate).service",state="active"} != 1
111 for: 20m
112 labels:
113 severity: warn
114
115 # todo: at some point, look into making mailtest-check either be resilient to the internet going down,
116 # or inhibit or group this alert with it going down.
117 - alert: sysd_result_fail
118 # not sure 30m is really needed, it prevents the alert from flapping
119 # i guess.
120 expr: |-
121 rate(node_systemd_unit_result_fail_count[30m]) > 0
122 labels:
123 severity: day
124
125 - alert: exim_paniclog
126 expr: |-
127 exim_paniclog > 0
128 labels:
129 severity: day
130
131 - alert: check_crypttab
132 expr: |-
133 check_crypttab > 0
134 labels:
135 severity: prod
136
137 # 17 minutes: We try to send every 5 minutes. if we reboot causing 1
138 # send to fail, thats 10 minutes between 2 sends. we test this every 5
139 # minutes, so thats 15 minutes of time we can expect for 1 failed email,
140 # and 1 failed email is expected due to reboots or other tiny issues we
141 # dont care about.
142 #
143 # cmc_wan_down etc, inhibits other alerts, but mailtest_check needs
144 # additional time to recover after an outage. We can only inhibit while
145 # an alert is actually firing, it doesnt affect the "for:"
146 # condition. So, we have those alerts that need to be delayed be
147 # conditioned on a query for that alert having not been firing in the
148 # last X minutes. However, there is a special case when prometheus
149 # itself was down, and so there was no alert. So, I test for missing
150 # of metric that gets generated for prometheus itself. If for some
151 # reason that has a problem, I could make it more conservative by
152 # checking that we booted recently instead, eg:
153 # time() - node_boot_time_seconds{instance="kdwg:9101"} <= 60 * 17
154 - alert: mailtest_check_vps
155 expr: |-
156 time() - mailtest_check_last_usec{job="tlsnode"} >= 60 * 17 unless on() mailtest_lag_inhibit
157 labels:
158 severity: day
159 annotations:
160 summary: '17 minutes down'
161
162 - alert: mailtest_check_mailhost
163 expr: |-
164 time() - max by (folder,from) (mailtest_check_last_usec{job="node"}) >= 60 * 17 unless on() mailtest_lag_inhibit
165 labels:
166 severity: day
167 annotations:
168 summary: '17 minutes down'
169
170 # 20 minutes. just allow for more due to prod alert.
171 - alert: mailtest_check_gnu_mailhost
172 expr: |-
173 time() - max by (folder,from) (mailtest_check_last_usec{folder="/m/md/l/testignore", from="iank@gnu.org"}) >= 60 * 20 unless on() mailtest_lag_inhibit
174 labels:
175 severity: prod
176 annotations:
177 summary: '20 minutes down'
178
179 - alert: mailtest_check_unexpected_spamd_vps
180 expr: |-
181 mailtest_check_unexpected_spamd_results >= 1
182 labels:
183 severity: day
184 annotations:
185 summary: 'jr -u mailtest-check -e'
186
187
188 # We expect to be getting metrics, if we come up and notice we have
189 # any missing in the past, and it wasn't from a reboot, and we haven't
190 # fired any other alerts, make an alert. In testing, the the count is
191 # 19 for 19 minutes, but I make it 18 just to give a bit of slack.
192 - alert: historical_missing_metric
193 expr: |-
194 count_over_time(up{job="prometheus"}[19m]) <= 18 unless on() present_over_time(ALERTS[19m]) unless on() time() - node_boot_time_seconds{instance="kdwg:9101"} <= 60 * 17
195 labels:
196 severity: warn
197
198 - alert: 1pmtest
199 expr: hour() == 17 and minute() < 5
200 for: 0m
201 labels:
202 severity: daytest
203 annotations:
204 summary: Prometheus daily test alert
205
206
207 #### Inhibit notes ####
208 ## Example of expressions to detect if the target_down alert
209 # fired in the last 24 hours. Initially, I thought his could
210 # be an alert which inhibits up_resets, but eventually I figured
211 # that doesn't make much sense, and the idea of using an alert
212 # that is not an indication of something wrong, only inhibits another
213 # alert, I think works better to integrate directly into the
214 # alert it would inhibit, this may mean a recording rule. That avoids
215 # an alert we have to ignore or filter out.
216 #
217 # Alternate expression, to calculate if the alert would have fired is:
218 # min_over_time(sum_over_time(up[30m])[1d:]) == 0
219 # where 30m matches the for: time in target_down
220 #
221 # Note: for graphing, surround in the expression in sum_over_time()
222 # ALERTS{alertname="target_down",alertstate="firing"}[1d]
223 #### end Inhibit notes ####
224
225
226 # For targets where we alert only on long downtimes, we
227 # still want to know if it is going down many times for short times over
228 # a long period of time. But ignore reboots.
229 #
230 ## Another way would be to detect an overall downtime:
231 # avg_over_time(node_systemd_unit_state{name="dynamicipupdate.service",state="active"}[1d]) < .95
232
233 # However, this seems to just find too many false positives for now, so
234 # commenting it out.
235
236 # - alert: up_resets
237 # expr: |-
238 # resets(up[1d]) - changes(node_boot_time_seconds[1d]) > 12
239 # labels:
240 # severity: warn
241 # annotations:
242 # summary: "Target has gone down {{ $value }} times in 1 day, > 12"
243
244
245
246 # https://awesome-prometheus-alerts.grep.to/rules
247
248 # todo, we should probably group the prometheus alerts that indicate a
249 # host-local problem.
250 # eg, set a label alert-group: local-prom, then make a receiver that
251 # groups by it when the alert-group is local-prom.
252
253 - name: awesome prometheus alerts
254 rules:
255
256 - alert: PrometheusJobMissing
257 expr: absent(up{job="prometheus"})
258 for: 30m
259 labels:
260 severity: day
261 annotations:
262 summary: Prometheus job missing (instance {{ $labels.instance }})
263 description: "A Prometheus job has disappeared\n VALUE = {{ $value }}"
264
265 - alert: lowpri_target_down
266 expr: up{instance!~"kdwg:9101|bkex.b8.nz:9101|liex.b8.nz:9101|10.2.0.1:9100"} == 0
267 for: 30m
268 labels:
269 severity: warn
270 annotations:
271 summary: Target down for 30m
272
273 - alert: target_down
274 expr: up{instance=~"kdwg:9101|bkex.b8.nz:9101|liex.b8.nz:9101|10.2.0.1:9100"} == 0
275 for: 5m
276 labels:
277 severity: day
278 annotations:
279 summary: High priority target down for 5m
280
281 - alert: target_down
282 expr: absent(present_over_time(mailtest_check_last_usec{folder="/m/md/l/testignore",from="ian@iankelling.org"}[5m]))
283 for: 5m
284 labels:
285 severity: day
286 annotations:
287 summary: MAIL_HOST likely down for 5m
288
289
290 # note, the next upstream metric is intentionally omitted:
291 # https://github.com/samber/awesome-prometheus-alerts/issues/283
292
293 - alert: PrometheusConfigurationReloadFailure
294 expr: prometheus_config_last_reload_successful != 1
295 for: 30m
296 labels:
297 severity: day
298 annotations:
299 description: "Prometheus configuration reload error\n VALUE = {{ $value }}"
300
301 - alert: PrometheusTooManyRestarts
302 expr: changes(process_start_time_seconds{job=~"prometheus|pushgateway|alertmanager"}[30m]) > 10
303 for: 0m
304 labels:
305 severity: warning
306 annotations:
307 description: "Prometheus has restarted more than ten times in the last 30 minutes. It might be crashlooping.\n VALUE = {{ $value }}"
308
309 - alert: PrometheusAlertmanagerJobMissing
310 expr: absent(up{job="alertmanager"})
311 for: 30m
312 labels:
313 severity: warn
314 annotations:
315 description: "A Prometheus AlertManager job has disappeared\n VALUE = {{ $value }}"
316
317 - alert: PrometheusAlertmanagerConfigurationReloadFailure
318 expr: alertmanager_config_last_reload_successful != 1
319 for: 30m
320 labels:
321 severity: day
322 annotations:
323 description: "AlertManager configuration reload error\n VALUE = {{ $value }}"
324
325 - alert: PrometheusNotConnectedToAlertmanager
326 expr: prometheus_notifications_alertmanagers_discovered < 1
327 for: 30m
328 labels:
329 severity: day
330 annotations:
331 description: "Prometheus cannot connect the alertmanager\n VALUE = {{ $value }}"
332
333 - alert: PrometheusRuleEvaluationFailures
334 expr: increase(prometheus_rule_evaluation_failures_total[3m]) > 0
335 for: 30m
336 labels:
337 severity: warn
338 annotations:
339 description: "Prometheus encountered {{ $value }} rule evaluation failures, leading to potentially ignored alerts.\n VALUE = {{ $value }}"
340
341 - alert: PrometheusTemplateTextExpansionFailures
342 expr: increase(prometheus_template_text_expansion_failures_total[3m]) > 0
343 for: 30m
344 labels:
345 severity: warn
346 annotations:
347 description: "Prometheus encountered {{ $value }} template text expansion failures\n VALUE = {{ $value }}"
348
349 - alert: PrometheusRuleEvaluationSlow
350 expr: prometheus_rule_group_last_duration_seconds > prometheus_rule_group_interval_seconds
351 for: 5m
352 labels:
353 severity: warn
354 annotations:
355 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 }}"
356
357 - alert: PrometheusNotificationsBacklog
358 expr: min_over_time(prometheus_notifications_queue_length[30m]) > 0
359 for: 0m
360 labels:
361 severity: warn
362 annotations:
363 description: "The Prometheus notification queue has not been empty for 10 minutes\n VALUE = {{ $value }}"
364
365 - alert: PrometheusAlertmanagerNotificationFailing
366 expr: rate(alertmanager_notifications_failed_total[1m]) > 0
367 for: 30m
368 labels:
369 severity: warn
370 annotations:
371 description: "Alertmanager is failing sending notifications\n VALUE = {{ $value }}"
372
373 # file_sd doesnt count as service discovery, so 0 is expected.
374 # - alert: PrometheusTargetEmpty
375 # expr: prometheus_sd_discovered_targets == 0
376 # for: 30m
377 # labels:
378 # severity: day
379 # annotations:
380 # description: "Prometheus has no target in service discovery\n VALUE = {{ $value }}"
381
382 - alert: PrometheusTargetScrapingSlow
383 expr: prometheus_target_interval_length_seconds{quantile="0.9"} > 90
384 for: 30m
385 labels:
386 severity: warn
387 annotations:
388 description: "Prometheus is scraping exporters slowly\n VALUE = {{ $value }}"
389
390 - alert: PrometheusLargeScrape
391 expr: increase(prometheus_target_scrapes_exceeded_sample_limit_total[10m]) > 10
392 for: 30m
393 labels:
394 severity: warn
395 annotations:
396 description: "Prometheus has many scrapes that exceed the sample limit\n VALUE = {{ $value }}"
397
398 - alert: PrometheusTargetScrapeDuplicate
399 expr: increase(prometheus_target_scrapes_sample_duplicate_timestamp_total[5m]) > 0
400 for: 30m
401 labels:
402 severity: warn
403 annotations:
404 description: "Prometheus has many samples rejected due to duplicate timestamps but different values\n VALUE = {{ $value }}"
405
406 - alert: PrometheusTsdbCheckpointCreationFailures
407 expr: increase(prometheus_tsdb_checkpoint_creations_failed_total[1m]) > 0
408 for: 30m
409 labels:
410 severity: warn
411 annotations:
412 description: "Prometheus encountered {{ $value }} checkpoint creation failures\n VALUE = {{ $value }}"
413
414 - alert: PrometheusTsdbCheckpointDeletionFailures
415 expr: increase(prometheus_tsdb_checkpoint_deletions_failed_total[1m]) > 0
416 for: 30m
417 labels:
418 severity: warn
419 annotations:
420 description: "Prometheus encountered {{ $value }} checkpoint deletion failures\n VALUE = {{ $value }}"
421
422 - alert: PrometheusTsdbCompactionsFailed
423 expr: increase(prometheus_tsdb_compactions_failed_total[1m]) > 0
424 for: 30m
425 labels:
426 severity: warn
427 annotations:
428 description: "Prometheus encountered {{ $value }} TSDB compactions failures\n VALUE = {{ $value }}"
429
430 - alert: PrometheusTsdbHeadTruncationsFailed
431 expr: increase(prometheus_tsdb_head_truncations_failed_total[1m]) > 0
432 for: 30m
433 labels:
434 severity: warn
435 annotations:
436 description: "Prometheus encountered {{ $value }} TSDB head truncation failures\n VALUE = {{ $value }}"
437
438 - alert: PrometheusTsdbReloadFailures
439 expr: increase(prometheus_tsdb_reloads_failures_total[1m]) > 0
440 for: 30m
441 labels:
442 severity: warn
443 annotations:
444 description: "Prometheus encountered {{ $value }} TSDB reload failures\n VALUE = {{ $value }}"
445
446 - alert: PrometheusTsdbWalCorruptions
447 expr: increase(prometheus_tsdb_wal_corruptions_total[1m]) > 0
448 for: 30m
449 labels:
450 severity: warn
451 annotations:
452 description: "Prometheus encountered {{ $value }} TSDB WAL corruptions\n VALUE = {{ $value }}"
453
454 - alert: PrometheusTsdbWalTruncationsFailed
455 expr: increase(prometheus_tsdb_wal_truncations_failed_total[1m]) > 0
456 for: 30m
457 labels:
458 severity: warn
459 annotations:
460 description: "Prometheus encountered {{ $value }} TSDB WAL truncation failures\n VALUE = {{ $value }}"