Alert on Key Metrics with Alertmanager

Learn to set up Alertmanager for key metrics in this practical Linux, networking, and telemetry tutorial. Step-by-step guidance, troubleshooting, and next steps included.

Focus: alert on key metrics with alertmanager

Sponsored

You've got dashboards full of metrics, but you only truly care when something breaks. Staring at graphs is not a monitoring strategy — it's the recipe for missed outages and 2 a.m. incident response chaos. This lesson shows you how to build a practical, rule-based alerting pipeline with Alertmanager, the component that turns raw metrics like node_cpu_seconds_total into actionable Slack, email, or webhook notifications. By the end, you'll confidently answer the question: "Is my system healthy right now?" without a single dashboard tab open.

The problem this lesson solves

Your server has a CPU spike. Your disk is filling up. Your API latency is skyrocketing. If you rely on a human to notice these signals on a graph, you've already lost. Dashboards are reactive — they require someone to watch them constantly, which doesn't scale beyond a single busy afternoon.

Alerting is the shift from watching to knowing. Instead of "I hope someone sees it," you get a proactive notification the moment a critical threshold is crossed. But alerting on raw metrics is noisy: a single 5-second CPU spike triggers ten emails, and you quickly learn to ignore every alert.

Alertmanager exists to solve this exactly. It's the decision engine that sits between your metrics and your notification channels. It deduplicates, routes, and suppresses alerts so you only get woken up when the cluster is genuinely on fire — not when one node sneezes.

Core concept / mental model

Think of your monitoring stack as a three-stage assembly line:

  1. Collectnode_exporter or your application scrapes system metrics (CPU, memory, disk, HTTP latency) and exposes them over /metrics.
  2. Evaluate — Prometheus runs alerting rules (defined in .rules.yml files) against those metrics, evaluating queries like up == 0 or node_filesystem_avail_bytes < 10% every 15 seconds.
  3. Notify — When a rule fires, Prometheus pushes an alert to Alertmanager. Alertmanager applies routing, grouping, and deduplication, then sends a notification to your chosen receiver: Slack, email, PagerDuty, or a generic webhook.

Key distinction: Prometheus evaluates rules; Alertmanager handles notifications. You don't configure the what in Alertmanager — you configure the who, when, and how.

In Alertmanager, you define three core concepts:

  • Receivers — the destination: email, slack, webhook, pagerduty. Each receiver has connection details, like SMTP server or Slack webhook URL.
  • Routing trees — a decision tree that maps incoming alerts to receivers based on labels like severity, team, or environment.
  • Grouping — a strategy to batch multiple related alerts into one notification, reducing noise. For example, group by alertname for Watchdog alerts.

Think of Alertmanager as the bouncer of your alerting party: it lets the important ones through, filters out the noise, and makes sure the right people get in.

How it works step by step

The flow from a metric to a notification involves these steps:

  1. Define an alerting rule in Prometheus. The rule file is YAML with groups, rules, and an expr (PromQL expression) that evaluates to true when the condition is met.
  2. Prometheus evaluates the rule at each scrape interval (default 15s). When the expression returns a value, the alert goes into pending state.
  3. After a configurable for duration (e.g., 2 minutes), the alert transitions to firing — this prevents flapping.
  4. Prometheus sends the firing alert to Alertmanager via an HTTP POST to /api/v1/alerts (Alertmanager URL is configured in prometheus.yml).
  5. Alertmanager loads its routing tree and assigns the alert to the first matching route.
  6. Alertmanager groups alerts with the same group key and deduplicates repeated notifications.
  7. Alertmanager sends a notification to the configured receiver (Slack, email, etc.).
  8. When the metric returns to normal, the rule resolves, and Alertmanager sends a resolved notification.

Hands-on walkthrough

Let's build a minimal-but-real alerting pipeline with Alertmanager. You'll need Docker or a Linux host with Prometheus and Alertmanager installed. We'll simulate a crash and watch the notification flow.

Step 1: Create an alerting rule

Create alerts.yml with a rule that fires when a node has been down for more than 1 minute:

# alerts.yml
groups:
  - name: instance_alerts
    rules:
      - alert: InstanceDown
        expr: up == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "Instance {{ $labels.instance }} down"

Step 2: Configure Prometheus to use the rule and point to Alertmanager

Add the rule file and Alertmanager URL to prometheus.yml:

# prometheus.yml
global:
  scrape_interval: 15s

rule_files:
  - "alerts.yml"

alerting:
  alertmanagers:
    - static_configs:
        - targets: ["localhost:9093"]

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

Step 3: Configure Alertmanager with a receiver

Create alertmanager.yml with an email receiver and a simple route:

# alertmanager.yml
route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 5m
  repeat_interval: 4h
  receiver: 'email'  # default
  routes:
    - matchers:
        - severity = critical
      receiver: 'email'
        # separate receiver for critical alerts
receivers:
  - name: 'email'
    email_configs:
      - to: 'oncall@example.com'
        from: 'alert@example.com'
        smarthost: 'smtp.example.com:587'
        auth_username: 'alert@example.com'
        auth_password: 'secret'

Step 4: Run the stack

If you're using Docker, start all three services:

# docker-compose.yml or docker run commands
docker run -d --name prometheus -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml -v $(pwd)/alerts.yml:/etc/prometheus/alerts.yml -p 9090:9090 prom/prometheus
docker run -d --name alertmanager -v $(pwd)/alertmanager.yml:/etc/alertmanager/alertmanager.yml -p 9093:9093 prom/alertmanager
docker run -d --name node-exporter -p 9100:9100 prom/node-exporter

Step 5: Trigger an alert and observe the flow

Stop the node-exporter container to simulate a failure:

docker stop node-exporter

After a minute, check the Alertmanager UI at http://localhost:9093 — you should see the InstanceDown alert in firing state. If email is configured, you'll get a notification. If no SMTP, use a webhook receiver to see the JSON payload.

Pro tip: Use amtool (Alertmanager's CLI) to test routing without firing real alerts: amtool check-config alertmanager.yml validates your config.

Compare options / when to choose what

Alertmanager is the default choice in the Prometheus ecosystem, but there are alternatives. Here's a comparison:

Tool Strengths Best for Integration
Alertmanager Native Prometheus integration, powerful routing/grouping Teams already on Prometheus Prometheus rules → Alertmanager
Grafana Alerting Unified alerting across dashboards and data sources, flexible notification policies Multi-source monitoring with Grafana as the frontend Grafana dashboards, Prometheus, Loki, CloudWatch
Kapacitor (InfluxDB ecosystem) Stream processing, anomaly detection, continuous queries InfluxDB time-series databases InfluxDB as primary storage

When to choose what:

  • Choose Alertmanager if you're already using Prometheus for scraping — it's the lowest-friction path and the natural place to manage alerts.
  • Choose Grafana Alerting if you have multiple data sources (Loki logs, CloudWatch metrics) and want a single alerting surface in Grafana.
  • Choose Kapacitor only if you're deeply invested in the InfluxDB stack and need anomaly detection beyond simple thresholds.

Troubleshooting & edge cases

  • Alert fires but no notification — Check Alertmanager logs (docker logs alertmanager). Most common causes: wrong receiver name in route, firewall blocking port 9093 from Prometheus, or routing matcher not matching any labels. Validate with amtool check-config.
  • Alert never reaches firing state — Your for duration is too long, or the expression has occasional gaps. Use amtool alert query to debug rule state. Try lowering for to 5s for testing.
  • Flapping alerts — Frequent notifications. Increase repeat_interval (e.g., 4h) and group_wait (e.g., 30s) to batch alerts and avoid re-notifying on every evaluation cycle.
  • Duplicate notifications across many alerts — Incorrect group_by settings. Use group_by: ['alertname', 'instance'] to group by alert and instance, so multiple instances down produce one notification, not many.
  • Silenced but still firing — You may have silenced the wrong route. Check that the silence matchers match all labels of the alert (e.g., include instance=~"node.*"). Use amtool silence query to verify.
  • Prometheus fails to start — Invalid rule file. Run promtool check rules alerts.yml to validate syntax.
  • Alertmanager fails to load config — Validate with amtool check-config; common issues are missing route or receivers blocks.

What you learned & what's next

You now understand the complete alerting pipeline: Prometheus evaluates alerting rules, Alertmanager routes and notifies. You can define alert rules on key metrics, configure receivers (email, Slack, webhook), and troubleshoot common issues like flapping, misconfiguration, and notification failures.

You've also gained practical skills: writing PromQL expressions in alert rules, structuring alertmanager.yml routing trees, and using amtool/promtool for validation. These are the exact skills you'll build on next.

Next lesson: In the following tutorial, we'll explore alert routing and silences — mastering advanced grouping, dynamic label matching, and time-based silences to keep your on-call team sane during maintenance windows.

Practice recap

Now set up your own Alertmanager pointed at a test Prometheus instance. Create a simple alert on up == 0, configure an email receiver (use the MailHog Docker image for SMTP), and stop a Prometheus target to trigger the alert. Observe the notification in your inbox and the resolved alert when you bring it back. This 20-minute exercise will solidify your understanding of the full pipeline.

Common mistakes

  • Forgetting to add the alerting block to prometheus.yml — without the Alertmanager URL, Prometheus never sends alerts.
  • Using a literal label match like severity=critical in route.matchers when the alert has the label severity: critical — the syntax is correct, but many users miss the matcher type and fail silently.
  • Configuring for: 1m but then testing with a 5-second downtime — the alert stays pending and never fires, confusing new users.
  • Setting repeat_interval too low (e.g., 1m) — Alertmanager will re-notify on every evaluation cycle, flooding your inbox.

Variations

  1. Use Grafana Alerting as an alternative if you want unified alerting across multiple data sources like Prometheus and Loki.
  2. Implement a custom webhook receiver in Python (using Flask or FastAPI) to integrate alerts with your own incident management system.
  3. Leverage Alertmanager's built-in high-availability mode with multiple replicas and --cluster.listen-address for production redundancy.

Real-world use cases

  • A backend platform team monitors node_exporter metrics and sets an alert for low disk space on database servers, receiving a Slack message when usage exceeds 85%.
  • A microservices organization routes critical alerts to PagerDuty for on-call engineers and uses grouping by service name so a single notification covers multiple failing instances.
  • A DevOps team silences maintenance-related alerts during scheduled deployments using Alertmanager's silence API and a custom regex matcher on environment labels.

Key takeaways

  • Alertmanager is the notification engine that receives alerts from Prometheus and sends them to receivers like email, Slack, or PagerDuty.
  • Prometheus evaluates alerting rules; Alertmanager handles routing, grouping, and deduplication — you configure the what in Prometheus and the who/how in Alertmanager.
  • Use for duration to avoid flapping alerts and repeat_interval to control notification frequency.
  • Always validate configs with amtool check-config and promtool check rules before deploying.
  • Master routing trees and label matchers to send alerts to the right team or service automatically.

Sponsored

Sponsored

Discussion

Questions, corrections, and tips help everyone reading this page.

0 comments

Add a comment

Shown publicly with your comment.

Be constructive · max 4,000 characters

No comments yet — start the thread.

Related tutorials, quizzes, and articles for this topic.