Chapter 11 · Lesson 7 of 10
Monitoring and logs

Alerting without alert fatigue: Prometheus and Alertmanager

Good alerting fires only on symptoms a human must act on, waits with a for duration to avoid blips, separates pages from tickets and uses Alertmanager to group, inhibit and silence notifications.

By the end you will

Write a Prometheus alert rule with a for duration and a runbook link, and understand grouping, inhibition and silences.

Time
25 min
Level
Intermediate
Check
4 questions
You need
  • Prometheus scraping at least one target
  • A chat or email destination for alerts

How an alert reaches the right person

Alerts fire only after a rule holds for a while, then Alertmanager routes urgent ones to a page and the rest to a ticket.
  1. A rule stays true for its whole for duration, so Prometheus sends a firing alert to Alertmanager.
  2. Alertmanager groups related alerts, skips silenced ones, and pages the person on call for a critical alert.
  3. A warning that can wait until working hours becomes a ticket or a chat message instead.
Static diagram
  1. PrometheusfiringAlertmanager
  2. AlertmanagercriticalPage
  3. AlertmanagerwarningTicket

Alert on symptoms users feel, not on every number that moves. Give each alert a for duration so brief spikes do not fire it, decide up front whether it pages a person or opens a ticket, let Alertmanager group related alerts into one message, and attach a runbook link so whoever receives it knows what to do. Fewer alerts that each demand action beat many that get ignored.

How it works#

Prometheus evaluates alert rules on a schedule. When an expression returns results, the alert becomes pending, and after the for duration it becomes firing. Prometheus sends firing alerts to Alertmanager, which handles delivery: grouping, deduplication, routing to receivers like email or a chat webhook, silences and inhibition. The diagram above shows that path. Prometheus decides what is wrong, Alertmanager decides who hears about it and how.

Alert fatigue happens when people receive many unimportant alerts and begin to ignore all of them. The fixes are social as much as technical: every alert must have an owner, an action and a reason to exist.

Alert on symptoms#

A symptom is what a user or the business feels: the site returns errors, pages take too long, checkout fails, a backup did not run. A cause is an internal fact that might lead to a symptom: CPU is high, a container restarted, swap is used.

Page on symptoms. Keep causes on dashboards, where you read them while investigating. Some causes are worth alerting on because they predict an unavoidable symptom soon, such as a disk that will be full in four hours. The first outside check from uptime checks with a script and timer is the model symptom alert.

Step 1: Write a rule with a for duration#

Create /etc/prometheus/rules/basic.yml:

yaml
groups:
  - name: basic
    rules:
      - alert: TargetDown
        expr: up == 0
        for: 5m
        labels:
          severity: page
        annotations:
          summary: "{{ $labels.instance }} is not being scraped"
          runbook_url: "https://example.com/runbooks/target-down"

      - alert: DiskAlmostFull
        expr: |
          node_filesystem_avail_bytes{mountpoint="/"}
            / node_filesystem_size_bytes{mountpoint="/"} < 0.10
        for: 15m
        labels:
          severity: ticket
        annotations:
          summary: "Less than 10 percent free on / at {{ $labels.instance }}"
          runbook_url: "https://example.com/runbooks/disk-full"

The for values are starting points. Short enough that a real outage is not delayed too long, long enough that a restart or a log burst does not wake anyone. The 10 percent figure is also a starting point, tuned in disk, memory and CPU alerts that matter.

Step 2: Validate and load the rules#

Reference the file in prometheus.yml:

yaml
rule_files:
  - /etc/prometheus/rules/*.yml

Check both before restarting:

bash
promtool check rules /etc/prometheus/rules/basic.yml
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl restart prometheus

Open the Alerts page in the Prometheus web UI, through an SSH tunnel, to see each rule as inactive, pending or firing. Keep that UI private, as covered in Prometheus and node exporter basics.

Step 3: Route, group and silence with Alertmanager#

A minimal alertmanager.yml groups by alert name and instance and sends the page severity to a webhook receiver:

yaml
route:
  receiver: ticket
  group_by: ["alertname", "instance"]
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  routes:
    - matchers:
        - severity="page"
      receiver: pager

receivers:
  - name: pager
    webhook_configs:
      - url: "https://example.com/hook"
  - name: ticket
    webhook_configs:
      - url: "https://example.com/hook-tickets"

inhibit_rules:
  - source_matchers:
      - alertname="TargetDown"
    target_matchers:
      - severity="ticket"
    equal: ["instance"]

Validate it with amtool check-config alertmanager.yml. Grouping means 20 servers failing at once send one message listing them. The inhibition rule mutes ticket-level alerts for a host while TargetDown is firing for it, since a dead host makes the rest noise. A silence is the manual version: mute matching alerts for a time window during planned maintenance, and let it expire by itself. Replace the example webhook URLs and keep any tokens out of the file in git.

Pages versus tickets#

Decide severity before the alert exists. A page means “someone must act now, and the user is affected or will be soon.” A ticket means “this needs fixing this week.” If you cannot say what a person would do at 3 a.m. after getting it, it is not a page. A certificate expiring in three weeks is a ticket. The site returning errors is a page. Mapping severities to receivers, as above, makes the choice mechanical.

Check it worked#

  • promtool check rules reports the number of rules found and no errors.
  • Stop node_exporter for longer than the for time and TargetDown goes pending, then firing.
  • One message arrives at the pager receiver, not one per minute.
  • Restart node_exporter and the alert resolves.
  • The runbook link in the message opens a page that says what to do.

Edge cases and gotchas#

  • No for, flappy alerts. A rule without for fires on any single bad sample, including during restarts.
  • Too long for. A 30 minute delay on a page means 30 minutes of unnoticed outage. Match it to how fast the problem hurts.
  • Silences forgotten. Always set an expiry and a comment. An indefinite silence is an alert you deleted without saying so.
  • Alertmanager itself fails silently. Watch that Prometheus can reach it, and consider an always-firing “heartbeat” alert that an external service expects.
  • Repeat intervals too short. Repeating the same alert every few minutes feels like spam. Hours is usually enough.
  • Runbooks rot. Review them after each incident. A wrong runbook is worse than none.

Troubleshooting#

SymptomLikely causeFix
promtool check rules prints FAILEDYAML or PromQL errorFix the line shown in the message
Alert stays pending foreverCondition flips on and offLengthen the window or use avg_over_time
Alert fires but no messagePrometheus not pointed at AlertmanagerAdd the alerting block with the target address
Message sent but not deliveredWebhook URL or token wrongTest the webhook with curl by hand
20 messages for one outageNo groupingSet group_by and group_wait
Alerts muted unexpectedlyActive silence or inhibitionList silences with amtool silence query
Rules file ignoredNot listed in rule_filesFix the glob path and restart
Alert never resolvesExpression still true or stale dataCheck the expression in the graph view

Quick reference#

bash
promtool check rules /etc/prometheus/rules/basic.yml
amtool check-config /etc/alertmanager/alertmanager.yml
amtool silence add alertname=DiskAlmostFull --duration=2h --comment="planned work"
amtool silence query

Next#

Write real rules in disk, memory and CPU alerts that matter.

Check what you learned4 questions
1Which is a symptom alert rather than a cause alert?
2What does for: 10m protect against?
3What is Alertmanager grouping for?
4Which severity should wake someone at night?

Frequently asked questions

What is alert fatigue?

It is when people receive so many alerts, many of them unimportant, that they start ignoring all of them. Real incidents then get missed. The cure is fewer alerts that each demand action.

What does the for clause do in a Prometheus alert?

It requires the condition to stay true for the given time before the alert fires. for 10m means the expression must hold for ten minutes, which filters out short spikes.

What is the difference between a silence and an inhibition in Alertmanager?

A silence mutes matching alerts for a set time, usually by hand during maintenance. An inhibition rule automatically mutes some alerts while another, more important alert is firing, such as muting service alerts when the whole host is down.

How do I test an alert rule file?

Run promtool check rules on the file. It checks syntax and expressions before Prometheus loads them.

Sources

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios