Skip to content

DevOps Operations / Service monitoring · Step 6 of 7

Lesson: Service AlertsSwitch
← DevOps Operations

Delivery and containers

Service Alerts

Write alerts that fire for real problems and tell someone what to do.

An alert is a message that asks a person to act. Too few and outages go unnoticed. Too many and people start ignoring them, which is called alert fatigue.

What deserves an alert

Interrupt someone when users are affected, or soon will be, and a human can do something about it. High error rates, very slow responses and a disk about to fill are good examples. A short CPU spike that harms nobody belongs on a dashboard.

Threshold and duration

A useful rule states what is measured, the limit, and how long it must stay past the limit:

text
5xx error rate above 2% for 5 minutes

The duration filters out brief blips. A longer duration means fewer false alarms but slower notice. Severity helps too: page someone for an outage, open a ticket for a disk that will fill next week.

A tiny check script

Real systems use monitoring software, but the idea fits in a few lines:

bash
#!/bin/sh
use=$(df --output=pcent / | tail -n 1 | tr -dc '0-9')
if [ "$use" -ge 90 ]; then
  logger -t disk-check -p user.warning "/ is ${use}% full"
fi

logger writes a message to the system log. The df --output option is from GNU coreutils and may not exist on other systems. Run the script every five minutes with a crontab line:

text
*/5 * * * * /usr/local/bin/disk-check.sh

The -t option tags the message, so you can read the results with sudo journalctl -t disk-check. This script sends no notification, and it repeats the message on every run while the disk stays full. Alerting tools handle grouping and repeats for you.

Make it actionable

Each alert should say what is wrong, where, how bad it is, and what to check first. Link to a short runbook, a written list of steps.

Also watch the watcher. If monitoring stops, silence looks the same as health. A common safeguard is a separate check that complains when an expected regular signal does not arrive.

After each alert ask whether it led to action. If not, change the limit or remove it.

Try it

Save the script on a test machine, make it executable with chmod +x, and lower the limit to 1 so it fires. Find the message with sudo journalctl -t disk-check --since "5 minutes ago". The processes and cron lab covers scheduling.

Check your understanding

Service Alerts

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.