13.8 Alerting — one disk threshold that matters
Why: the problem
A team at a Pune startup set 40 alerts on day one. CPU above 50%, memory above 60%, every small thing. Within a week the Slack channel had 900 alerts. People muted the channel. Then one night the disk really filled up and the real alert was lost in the noise. Customers could not pay for three hours. This is called alert fatigue. A good alert is like a smoke alarm: it rings rarely, and when it rings, you must act. The rule is simple: alert on things that need a human now, wait a few minutes before firing so one blip does not wake anyone, and send it to the right person. Prometheus writes alert rules, and Alertmanager groups them, removes duplicates and sends them to Slack, email or PagerDuty. That is why we start with one alert that matters: the disk filling up.
What we will build
You will write three alert rules (disk almost full, server down, high error rate) and test them with promtool unit tests. Then you will run Alertmanager and route alerts to Slack, with critical alerts also going to email. Finally you will fill a test disk on purpose and watch the alert go from inactive to pending to firing, then resolve.
What: every term in plain English
- Alert rule — A PromQL condition plus a time. When it is true for that time, an alert fires.
- for: — How long the condition must stay true before firing. Stops alerts on short blips.
- Pending — The condition is true but the for time has not passed yet.
- Firing — The alert is active and sent to Alertmanager.
- Alertmanager — A separate program that groups, removes duplicates, silences and sends alerts.
- Route / receiver — Rules that decide who gets which alert, and where (Slack, email, PagerDuty).
- Severity — A label like warning or critical that decides urgency.
- Silence — A pause on matching alerts during planned work.
How: step by step
-
Write the rules file
Create rules/alerts.yml from Example 1What it does: Three alerts that matter.
Output
(no output) -
Check it
promtool check rules rules/alerts.ymlWhat it does: Validates the file.
Output
SUCCESS: 3 rules found -
Add Alertmanager to Compose
See Example 2What it does: A new service on port 9093.
Output
Container monstack-alertmanager-1 Started -
Tell Prometheus where Alertmanager is
alerting: section in prometheus.yml (Example 2)What it does: Prometheus sends firing alerts there.
Output
(no output) -
Reload Prometheus
curl -X POST localhost:9090/-/reloadWhat it does: Loads rules and the alerting section.
Output
(no output) -
See alerts
Browser: http://SERVER_IP:9090/alertsWhat it does: Each rule shows inactive, pending or firing.
Output
DiskAlmostFull (0 active)
Example 1: Three alert rules that matter
Stack. Prometheus alerting rules
Goal. Three alert rules that matter.
rules/alerts.yml
groups:
- name: core-alerts
rules:
- alert: DiskAlmostFull
expr: 100 * (1 - node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) > 85
for: 10m
labels:
severity: warning
annotations:
summary: "Disk {{ $labels.mountpoint }} on {{ $labels.instance }} is {{ printf \"%.0f\" $value }}% full"
runbook: "https://wiki.example.in/runbooks/disk-full"
- alert: InstanceDown
expr: up == 0
for: 2m
labels:
severity: critical
annotations:
summary: "{{ $labels.instance }} of job {{ $labels.job }} is down"
- alert: HighErrorRate
expr: sum by (job) (rate(http_requests_total{status=~"5.."}[5m])) / sum by (job) (rate(http_requests_total[5m])) > 0.05
for: 5m
labels:
severity: critical
annotations:
summary: "{{ $labels.job }} error rate is {{ $value | humanizePercentage }}"
What each line does
alert: DiskAlmostFull— The alert name. Use clear CamelCase names.expr: ... > 85— True when disk used is above 85%.for: 10m— Must stay true 10 minutes. A quick temp file will not page anyone.severity: warning— Warning goes to Slack only. Critical also pages.annotations.summary— The human message, with labels and the value filled in.runbook— Link to the steps to fix. Every alert should have one.up == 0 for 2m— Target down for 2 minutes.> 0.05— More than 5% of requests failing.
Green output
$ promtool check rules rules/alerts.yml
Checking rules/alerts.yml
SUCCESS: 3 rules found
Expected result. Three rules: one for capacity, one for availability, one for user pain. That is a better start than 40 noisy rules.
Example 2: Alertmanager routing to Slack and email
Stack. Alertmanager, Slack, Amazon SES
Goal. Alertmanager routing to Slack and email.
alertmanager.yml
global:
resolve_timeout: 5m
route:
receiver: slack-ops
group_by: [alertname, instance]
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
routes:
- matchers: [severity="critical"]
receiver: slack-and-email
receivers:
- name: slack-ops
slack_configs:
- api_url_file: /etc/alertmanager/slack_url
channel: "#ops-alerts"
send_resolved: true
title: "{{ .CommonAnnotations.summary }}"
- name: slack-and-email
slack_configs:
- api_url_file: /etc/alertmanager/slack_url
channel: "#ops-alerts"
send_resolved: true
email_configs:
- to: oncall@example.in
from: alerts@example.in
smarthost: email-smtp.ap-south-1.amazonaws.com:587
auth_username: SES_SMTP_USER
auth_password_file: /etc/alertmanager/ses_pass
Add to compose.yaml and prometheus.yml
# compose.yaml (under services:)
alertmanager:
image: prom/alertmanager:v0.27.0
volumes:
- ./alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro
- ./secrets/slack_url:/etc/alertmanager/slack_url:ro
- ./secrets/ses_pass:/etc/alertmanager/ses_pass:ro
ports:
- "9093:9093"
# prometheus.yml (top level)
alerting:
alertmanagers:
- static_configs:
- targets: ["alertmanager:9093"]
What each line does
group_by: [alertname, instance]— Alerts with the same name and server become one message.group_wait: 30s— Wait 30 seconds to collect related alerts before the first message.repeat_interval: 4h— If still firing, remind every 4 hours, not every minute.matchers: [severity="critical"]— Critical alerts go to the second receiver.api_url_file— The Slack webhook is read from a file, never written in the config in Git.send_resolved: true— Also tells you when it is fixed.smarthost ... :587— Amazon SES SMTP in Mumbai for email.auth_password_file— Password from a file. Keep secrets out of Git.
Green output
$ sudo docker run --rm -v $PWD:/c --entrypoint amtool prom/alertmanager:v0.27.0 check-config /c/alertmanager.yml
Checking '/c/alertmanager.yml' SUCCESS
Found:
- global config
- route
- 0 inhibit rules
- 2 receivers
- 0 templates
Expected result. Alertmanager config is valid. Warning alerts go to #ops-alerts; critical ones go to Slack and the on-call email.
Example 3: Fire the disk alert on purpose, and unit-test it
Stack. Prometheus, Alertmanager, promtool test rules
Goal. Fire the disk alert on purpose, and unit-test it.
Fill a lab disk (only on a lab VM)
df -h /
# make a big file until disk is above 85%
sudo fallocate -l 4G /var/tmp/fill.bin
df -h /
# watch the alert state every 30 seconds
watch -n 30 "curl -s localhost:9090/api/v1/alerts | grep -o '\"state\":\"[a-z]*\"'"
tests/disk_test.yml
rule_files:
- ../rules/alerts.yml
evaluation_interval: 1m
tests:
- interval: 1m
input_series:
- series: 'node_filesystem_avail_bytes{mountpoint="/",instance="web1"}'
values: '10x20'
- series: 'node_filesystem_size_bytes{mountpoint="/",instance="web1"}'
values: '100x20'
alert_rule_test:
- eval_time: 15m
alertname: DiskAlmostFull
exp_alerts:
- exp_labels: {severity: warning, mountpoint: "/", instance: web1}
What each line does
fallocate -l 4G— Creates a 4 GB file instantly. Easy to delete later./api/v1/alerts— Lists active alerts and their state.values: 10x20— The value 10 repeated for 20 minutes: 10 free out of 100 = 90% used.eval_time: 15m— Check at minute 15, after the for: 10m has passed.exp_alerts— The alert we expect to be firing with these labels.
Green output
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 14G 6.0G 70% /
/dev/xvda1 20G 18G 2.0G 90% /
21:50 "state":"pending"
22:00 "state":"firing"
Slack #ops-alerts: [FIRING:1] Disk / on 10.0.1.12:9100 is 90% full
$ promtool test rules tests/disk_test.yml
Unit Testing: tests/disk_test.yml
SUCCESS
Expected result. You saw the full life of an alert: pending for 10 minutes, firing, message in Slack. After rm /var/tmp/fill.bin it resolves and Slack shows [RESOLVED].
Verify: did it work?
-
Alertmanager connected?
curl -s localhost:9090/api/v1/alertmanagers | grep -o '"url":"[^"]*"'What it does: Shows the Alertmanager URL.
Output
"url":"http://alertmanager:9093/api/v2/alerts" -
Send a test alert
sudo docker compose exec alertmanager amtool alert add TestAlert severity=warning --annotation=summary="test from lab" --alertmanager.url=http://localhost:9093What it does: A test message should reach Slack.
Output
(no output; Slack shows [FIRING:1] TestAlert)
When it is red 1
Alert is firing in Prometheus but nothing in Slack
Cause. Prometheus does not know Alertmanager, or the Slack webhook file is wrong.
Fix, step by step
- Check /api/v1/alertmanagers on Prometheus.
- Check Alertmanager logs: sudo docker compose logs alertmanager | tail
- Test the webhook with curl -X POST -d '{"text":"hi"}' using your webhook URL.
When it is red 2
err="template: ... undefined variable \"$labels\""
Cause. In Alertmanager templates you use .Labels, not $labels. $labels is only for Prometheus rule annotations.
Fix, step by step
- Use {{ .CommonLabels.instance }} in alertmanager.yml.
- Keep {{ $labels.instance }} in rules files.
- Run amtool check-config.
When it is red 3
Same alert arrives 50 times
Cause. group_by is too detailed or repeat_interval is too short.
Fix, step by step
- Group by alertname and instance only.
- Set repeat_interval: 4h.
- Add an inhibit rule so InstanceDown hides other alerts from that server.
Cleanup
-
Delete the fill file
sudo rm -f /var/tmp/fill.bin && df -h /What it does: Frees the disk; the alert resolves after the next checks.
Output
/dev/xvda1 20G 14G 6.0G 70% / -
Silence during planned work
amtool silence add instance="10.0.1.12:9100" --duration=1h --comment="kernel patching" --alertmanager.url=http://localhost:9093What it does: Pauses alerts for one server for one hour.
Output
a4c1b9d2-5f3e-4b8a-9c11-2d7e6f0a1b3c
Ravindra Bagale's Tip
An alert is a smoke alarm. It should ring rarely — but when it rings, get up and act. Not 40 alerts — 3 good ones.
Alert म्हणजे smoke alarm. कमी वेळा वाजला पाहिजे, पण वाजला की उठून काम करायचं. ४० alert नको, ३ चांगले alert.
Alert यानी smoke alarm. कम बार बजना चाहिए, लेकिन बजे तो उठकर काम करो. ४० alert नहीं, ३ अच्छे alert.
Practice tasks
Easy Add a runbook to every alert
Why: At 2 a.m. the runbook link saves 20 minutes.
What to do: Add a runbook annotation to InstanceDown and HighErrorRate.
- Write a short wiki page for each.
- Add runbook: URL in annotations.
Check: Every alert in Slack has a link.
Medium Inhibit rule
Why: When a server is down, its disk and CPU alerts are noise.
What to do: Add an inhibit rule: InstanceDown hides other alerts with the same instance.
- inhibit_rules: source_matchers alertname="InstanceDown", target_matchers severity="warning", equal: [instance]
Check: Only InstanceDown arrives when the server is off.
Hard CloudWatch twin alarm
Why: Many teams keep a CloudWatch alarm as a backup if Prometheus itself is down.
What to do: Create a CloudWatch alarm on disk_used_percent above 85 for 10 minutes.
- Use the CWAgent namespace from lesson 13.3.
- Send to an SNS topic.
Check: Both Prometheus and CloudWatch fire for the same full disk.
Easy Say alerting in two lines
Why: If you can say it simply, you understand it. Juniors and interviewers both want the short version first.
What to do: Write two short lines about alerting for a fresher who knows only Linux, Git and Docker basics.
- Write the problem it solves.
- Write the one command, query or config line you use for it.
- Read it aloud to a friend.
Check: A fresher understands it without asking a question.
Easy Keep a throwaway monitoring lab
Why: Practice needs a lab you can break. If it gets messy, you delete the containers and start again in one minute.
What to do: Run Node Exporter in Docker and read its metrics page.
- docker run -d --name ne -p 9100:9100 prom/node-exporter
- curl -s localhost:9100/metrics | grep node_load1
- docker rm -f ne
Check: You see a line that starts with node_load1 and a number.
Medium Do it on a second stack
Why: Monitoring ideas must work on Prometheus and on CloudWatch. Only the tool changes, not the thinking.
What to do: Repeat this lesson on a different stack than the one you used first.
- If you used Prometheus, try the CloudWatch console or AWS CLI.
- Keep the same question: is it up, is it fast, is it failing, is it full?
- Compare the two graphs side by side.
Check: Both tools answer the same question with a number and a graph.
Medium Break it on purpose
Why: You must know the red error by face. During an outage there is no time to read slowly.
What to do: Cause one error from the "When it is red" part of this lesson and fix it.
- Follow the error section.
- Copy the exact message into your notes.
- Write the fix in one line.
Check: You fixed it using only the steps, without searching the web.
Medium Write a one-page runbook
Why: At 2 a.m. nobody remembers PromQL. A short page saves the on-call person.
What to do: Write a one-page runbook for this lesson.
- Title, when the alert fires, the graph to open, the exact commands, how to check, how to undo.
Check: A teammate can follow it alone, without calling you.
Hard Explain it like an interview
Why: Interviewers want real stories, not definitions.
What to do: Record a 60 second answer about this lesson.
- Say the problem, the metric you watched, the number you saw and the fix.
Check: Your answer has a real metric name and a real number.
Hard Draw the flow top to bottom
Why: A drawing shows where a number is born and where it ends up.
What to do: Draw this lesson as boxes from top to bottom.
- Start at the server or app, go through the exporter, Prometheus or CloudWatch, then Grafana, then the alert on your phone.
Check: Each box matches a real command or file in this lesson.
Homework: try at home
Try at home
At home, add an alert "BackupTooOld" that fires when the backup metric from lesson 13.5 is older than 26 hours. Write a promtool unit test for it and make the test pass.
Recap
- A good alert is rare, needs a human, and has a runbook.
- Use for: to skip short blips.
- Prometheus fires alerts; Alertmanager groups and sends them.
- Keep webhook URLs and passwords in files or secrets, not in Git.
- Test rules with promtool and with a real filled disk on a lab VM.
FAQ
Why 85% and not 95% for disk?
At 95% you may have only minutes left. 85% gives time to act calmly.
Should I alert on CPU above 80%?
Usually no. Alert on user pain (errors, latency). High CPU alone is often fine.
Can I send alerts to Microsoft Teams or WhatsApp?
Teams has a built-in receiver (msteams_configs). For others use a webhook bridge.
What is PagerDuty or Opsgenie?
On-call tools that call your phone and escalate if you do not answer.
Prometheus alerts or Grafana alerts?
Either works. Prometheus rules in Git with Alertmanager is the most common pattern.
What is an SLO alert?
An alert on how fast you burn your error budget, which is the most user-focused style.
Interview questions
-
How do you reduce alert fatigue?
Alert on symptoms not causes, use for: durations, group alerts, set severities, add inhibit rules, delete alerts nobody acts on, and add runbooks.
-
Explain the alert lifecycle in Prometheus.
Inactive, then pending while the for: time runs, then firing; Prometheus sends it to Alertmanager which groups, dedupes, routes and notifies; it resolves when the condition is false.
-
What is the role of Alertmanager?
Grouping, deduplication, routing to receivers, silences and inhibition.
-
How do you test alert rules?
promtool test rules with input series and expected alerts, plus a controlled real test on a lab system.
-
How do you avoid secrets in alertmanager.yml?
Use api_url_file and password_file pointing to mounted secrets, or a secrets manager with an init container.
Quick quiz
Q1. What does for: 10m do?
The condition must stay true 10 minutes before firing.
Q2. What is alert fatigue?
So many alerts that people ignore them, and miss real ones.
Q3. Which tool groups and routes alerts?
Alertmanager.
Q4. What is a silence?
A pause on matching alerts during planned work.
Q5. Which command tests rules with fake data?
promtool test rules.
Did you understand? Let us try it once more.
Revision card
Interview card