Prometheus Alertmanager: Alert Rules, Routing & Slack Notifications (Rocky Linux 10)

Prometheus is excellent at collecting metrics and deciding when something is wrong, but it does not send emails or chat messages. That job belongs to Alertmanager: it receives alerts from Prometheus, removes duplicates, groups related alerts into a single message, silences or inhibits noise, and routes notifications to the right place, such as a Slack channel.

This guide builds the complete alerting chain on Rocky Linux 10: install Alertmanager as a systemd service, write useful alert rules, connect Prometheus, route by severity to Slack, add inhibition and maintenance windows, and test everything with promtool, amtool, and a fake alert.

Table of Contents

  1. How alerting works in Prometheus
  2. Prerequisites
  3. Step 1: Create a Slack incoming webhook
  4. Step 2: Install Alertmanager
  5. Step 3: Write alert rules
  6. Step 4: Connect Prometheus to Alertmanager
  7. Step 5: Configure routing and Slack
  8. Understanding grouping and timing
  9. Inhibition, silences and maintenance windows
  10. Test the whole chain
  11. High availability
  12. Alert design that people actually respond to
  13. Firewall and SELinux
  14. Troubleshooting
  15. FAQ

1. How alerting works in Prometheus

 +-------------+  scrape   +-------------------------+
 | Targets     | <-------- |  Prometheus             |
 | node_exporter           |  evaluates alert rules  |
 | exporters, apps         |  every evaluation_interval
 +-------------+           +-----------+-------------+
                                       | pending --> firing   (rule "for:" duration)
                                       | POST /api/v2/alerts
                                       v
                           +-------------------------+
                           |  Alertmanager :9093     |
                           |   1. deduplicate        |
                           |   2. group              |
                           |   3. inhibit / silence  |
                           |   4. route              |
                           +-----------+-------------+
                                       |
                 +---------------------+----------------------+
                 v                     v                      v
            Slack channel          Email / webhook        On-call tool
          (warnings, info)        (reports, tickets)     (critical pages)
ConceptMeaning
Alert ruleA PromQL expression plus a for: duration; lives in Prometheus
PendingThe expression is true but has not yet lasted for the for: time
FiringThe alert is active and is sent to Alertmanager
RouteA rule in the routing tree that picks a receiver based on labels
ReceiverA destination: Slack, email, webhook, PagerDuty, and others
InhibitionSuppress some alerts while another, more important one is firing
SilenceA temporary mute created by a person, for maintenance

2. Prerequisites

RequirementDetail
ServerRocky Linux 10 with Prometheus already running; see Prometheus and Grafana on Rocky Linux 10
MetricsAt least node_exporter targets so there is something to alert on
SlackA workspace where you can add an app, and a channel such as #alerts
InternetThe Alertmanager host must reach hooks.slack.com over HTTPS
Accesssudo

3. Step 1: Create a Slack incoming webhook

  1. In Slack, open Apps and create (or open) an app for alerting via the Slack API site, then enable Incoming Webhooks.
  2. Choose Add New Webhook to Workspace, pick the #alerts channel, and copy the webhook URL. It looks like https://hooks.slack.com/services/T000/B000/XXXX.
  3. Treat the URL as a secret: anyone who has it can post to your channel.

Store it in a file readable only by the Alertmanager user (we will do this in step 2) rather than pasting it into the main config.

4. Step 2: Install Alertmanager

Check the latest release on the official Prometheus download page and set the version variable accordingly. Verify the SHA-256 checksum from the release’s checksum file before installing.

# Set to the version you verified on the official download page
AM_VERSION=0.32.0

cd /tmp
curl -fsSLO "https://github.com/prometheus/alertmanager/releases/download/v${AM_VERSION}/alertmanager-${AM_VERSION}.linux-amd64.tar.gz"
curl -fsSLO "https://github.com/prometheus/alertmanager/releases/download/v${AM_VERSION}/sha256sums.txt"
grep "alertmanager-${AM_VERSION}.linux-amd64.tar.gz" sha256sums.txt | sha256sum -c -

tar xzf "alertmanager-${AM_VERSION}.linux-amd64.tar.gz"
sudo install -m 0755 "alertmanager-${AM_VERSION}.linux-amd64/alertmanager" /usr/local/bin/alertmanager
sudo install -m 0755 "alertmanager-${AM_VERSION}.linux-amd64/amtool"       /usr/local/bin/amtool
alertmanager --version

Create a dedicated user and directories:

sudo useradd --system --no-create-home --shell /sbin/nologin alertmanager
sudo mkdir -p /etc/alertmanager/templates /var/lib/alertmanager
sudo chown -R alertmanager:alertmanager /var/lib/alertmanager
sudo chown -R root:alertmanager /etc/alertmanager
sudo chmod 750 /etc/alertmanager

# Slack webhook secret in its own file
sudo install -m 0640 -o root -g alertmanager /dev/null /etc/alertmanager/slack_webhook_url
echo 'https://hooks.slack.com/services/T000/B000/XXXX' | sudo tee /etc/alertmanager/slack_webhook_url > /dev/null

Create the systemd unit /etc/systemd/system/alertmanager.service:

[Unit]
Description=Prometheus Alertmanager
Wants=network-online.target
After=network-online.target

[Service]
User=alertmanager
Group=alertmanager
Type=simple
ExecStart=/usr/local/bin/alertmanager \
  --config.file=/etc/alertmanager/alertmanager.yml \
  --storage.path=/var/lib/alertmanager \
  --web.listen-address=127.0.0.1:9093
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
NoNewPrivileges=true
ProtectSystem=full
ProtectHome=true

[Install]
WantedBy=multi-user.target

--web.listen-address=127.0.0.1:9093 keeps the UI and API local. Change it only when you have put authentication or a reverse proxy in front.

5. Step 3: Write alert rules

Alert rules live on the Prometheus server. Create /etc/prometheus/rules/node-alerts.yml:

groups:
  - name: node-alerts
    rules:
      - alert: InstanceDown
        expr: up == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "{{ $labels.instance }} is down"
          description: "Prometheus could not scrape {{ $labels.job }} on {{ $labels.instance }} for 2 minutes."

      - alert: HighCpuUsage
        expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 85
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "High CPU on {{ $labels.instance }}"
          description: "CPU usage has been above 85% for 10 minutes (now {{ $value | printf \"%.0f\" }}%)."

      - alert: HighMemoryUsage
        expr: (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100 > 90
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "High memory usage on {{ $labels.instance }}"
          description: "Memory usage is {{ $value | printf \"%.0f\" }}%."

      - alert: DiskSpaceLow
        expr: (node_filesystem_avail_bytes{fstype!~"tmpfs|overlay|squashfs"} / node_filesystem_size_bytes{fstype!~"tmpfs|overlay|squashfs"}) * 100 < 15
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "Disk almost full on {{ $labels.instance }} ({{ $labels.mountpoint }})"
          description: "Only {{ $value | printf \"%.0f\" }}% free."

      - alert: DiskWillFillIn24h
        expr: predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs|overlay|squashfs"}[6h], 24 * 3600) < 0
        for: 30m
        labels:
          severity: critical
        annotations:
          summary: "{{ $labels.mountpoint }} on {{ $labels.instance }} is predicted to fill within 24 hours"
          description: "Based on the last 6 hours of growth."

      - alert: SystemdServiceFailed
        expr: node_systemd_unit_state{state="failed"} == 1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Unit {{ $labels.name }} failed on {{ $labels.instance }}"

The systemd collector must be enabled on node_exporter (--collector.systemd) for the last rule. The for: duration prevents flapping: a brief CPU spike does not page anyone.

Validate before loading:

promtool check rules /etc/prometheus/rules/node-alerts.yml

6. Step 4: Connect Prometheus to Alertmanager

Edit /etc/prometheus/prometheus.yml:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

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

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

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ["127.0.0.1:9090"]
  - job_name: node
    static_configs:
      - targets: ["127.0.0.1:9100"]
  - job_name: alertmanager
    static_configs:
      - targets: ["127.0.0.1:9093"]
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl reload prometheus      # or restart if reload is not enabled

Scraping Alertmanager’s own metrics lets you alert on notification failures later.

7. Step 5: Configure routing and Slack

Create /etc/alertmanager/alertmanager.yml:

global:
  resolve_timeout: 5m

templates:
  - /etc/alertmanager/templates/*.tmpl

route:
  receiver: slack-default
  group_by: ["alertname", "instance"]
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  routes:
    - matchers:
        - severity="critical"
      receiver: slack-critical
      group_wait: 10s
      repeat_interval: 1h
    - matchers:
        - severity="warning"
      receiver: slack-default

receivers:
  - name: slack-default
    slack_configs:
      - api_url_file: /etc/alertmanager/slack_webhook_url
        channel: "#alerts"
        send_resolved: true
        title: '[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }}'
        text: >-
          {{ range .Alerts }}
          *{{ .Annotations.summary }}*
          {{ .Annotations.description }}
          {{ end }}

  - name: slack-critical
    slack_configs:
      - api_url_file: /etc/alertmanager/slack_webhook_url
        channel: "#alerts-critical"
        send_resolved: true
        color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
        title: ':rotating_light: [{{ .Status | toUpper }}] {{ .CommonLabels.alertname }}'
        text: >-
          {{ range .Alerts }}
          *{{ .Annotations.summary }}*
          {{ .Annotations.description }}
          {{ end }}

inhibit_rules:
  - source_matchers:
      - severity="critical"
    target_matchers:
      - severity="warning"
    equal: ["alertname", "instance"]
  - source_matchers:
      - alertname="InstanceDown"
    target_matchers:
      - severity=~"warning|critical"
    equal: ["instance"]

Key points:

  • Use matchers (the current syntax) instead of the older match and match_re fields.
  • api_url_file reads the webhook from a file so the secret is not stored in the main config, which you may keep in Git.
  • send_resolved: true posts a message when the problem clears, so people know it is over.
  • Create the #alerts-critical channel and add the same webhook app to it, or route everything to one channel until you need the split.
  • Slack webhook routing to a different channel depends on your Slack app settings; webhook URLs created through the current app flow post to the channel chosen when the webhook was created. If the channel: override is ignored, create one webhook per channel and use a separate api_url_file for each receiver.

Validate and start:

sudo -u alertmanager amtool check-config /etc/alertmanager/alertmanager.yml
sudo systemctl daemon-reload
sudo systemctl enable --now alertmanager
systemctl status alertmanager --no-pager
curl -s http://127.0.0.1:9093/-/healthy

Reload after later config changes without a restart:

sudo systemctl reload alertmanager
# or: curl -X POST http://127.0.0.1:9093/-/reload

8. Understanding grouping and timing

Three timers shape notifications, and misunderstanding them is the usual cause of “too many” or “too few” alerts.

SettingMeaningTypical value
group_byLabels that define one notification groupalertname, instance (or cluster, service)
group_waitHow long to wait after the first alert of a new group before sending, so related alerts can join30s (10s for critical)
group_intervalHow long to wait before sending an update about new alerts added to an existing group5m
repeat_intervalHow often to re-send a notification for alerts that are still firing4h (1h for critical)
 time -->  0s          30s                          5m30s                     4h
 alert A   firing
 alert B        firing
              \__ group_wait __/
                   |
                   +-- notification #1 (A+B) 
                                      alert C fires -->  +-- notification #2 (A+B+C), after group_interval
                                                                                  ... still firing ... +-- repeat (every repeat_interval)

Group by labels that reflect how a human thinks about the incident. Grouping by alertname alone gives one message when 50 servers have a full disk; grouping by instance too gives 50 messages. Pick the level where one message equals one unit of work.

9. Inhibition, silences and maintenance windows

Inhibition is automatic suppression defined in the config. The rules above do two things:

  1. If a critical alert fires, the matching warning for the same alertname and instance is hidden.
  2. If InstanceDown fires for a host, all other alerts for that host are hidden (there is no point reporting high CPU on a machine that is unreachable).

Silences are temporary mutes created by a person, for example during maintenance:

# Silence all alerts for one host for 2 hours
amtool --alertmanager.url=http://127.0.0.1:9093 silence add instance="web01:9100" \
  --duration=2h --author="ramansah" --comment="Kernel update"

amtool --alertmanager.url=http://127.0.0.1:9093 silence query
amtool --alertmanager.url=http://127.0.0.1:9093 silence expire <silence-id>

Time intervals let a route behave differently at certain times, for example sending only critical alerts overnight:

time_intervals:
  - name: office-hours
    time_intervals:
      - weekdays: ["monday:friday"]
        times:
          - start_time: "08:00"
            end_time: "18:00"
        location: "Asia/Jakarta"

route:
  routes:
    - matchers: [severity="warning"]
      receiver: slack-default
      active_time_intervals: [office-hours]

Check the exact behavior in the documentation for your version before relying on this in production.

10. Test the whole chain

1. Send a fake alert directly to Alertmanager:

curl -s -X POST http://127.0.0.1:9093/api/v2/alerts \
  -H 'Content-Type: application/json' \
  -d '[{
    "labels": {"alertname":"TestAlert","severity":"warning","instance":"test:9100"},
    "annotations": {"summary":"This is a test alert","description":"Sent with curl to verify Slack routing."}
  }]'

After group_wait (30 seconds) a message should appear in Slack. Check how Alertmanager sees the routing:

amtool --alertmanager.url=http://127.0.0.1:9093 alert
amtool config routes test --config.file=/etc/alertmanager/alertmanager.yml severity=critical alertname=InstanceDown

2. Trigger a real rule. Stop node_exporter on a test host and watch InstanceDown move from pending to firing:

sudo systemctl stop node_exporter
# Prometheus UI: http://<prometheus>:9090/alerts
sudo systemctl start node_exporter       # you should receive a RESOLVED message

3. Verify metrics about delivery:

curl -s http://127.0.0.1:9093/metrics | grep -E 'alertmanager_notifications_(total|failed_total)'

11. High availability

Run two or more Alertmanager instances as a cluster so a single failure does not silence your alerts. They gossip to share silences and notification state, so you do not receive duplicates.

# Node 1
alertmanager --config.file=... --cluster.listen-address=0.0.0.0:9094 --cluster.peer=am2.example.com:9094
# Node 2
alertmanager --config.file=... --cluster.listen-address=0.0.0.0:9094 --cluster.peer=am1.example.com:9094

Point every Prometheus server at all Alertmanager instances (list them in alertmanagers), not at a load balancer. Allow the cluster port between the nodes only.

Also monitor the monitor: Prometheus should be alerted on by something independent, such as a “dead man’s switch” (an always-firing alert sent to an external heartbeat service) so you learn when the alerting pipeline itself is broken.

12. Alert design that people actually respond to

PrinciplePractice
Alert on symptoms, not every causePage for “users see errors” or “disk will fill”, not for every CPU blip
Every alert needs an actionIf nobody should do anything, it is a dashboard, not an alert
Use for:Avoid flapping and brief spikes
Two or three severitiescritical = act now, warning = act during working hours, info = no notification
Write helpful annotationsInclude what, where, how bad, and a link to a runbook
Predictive alerts for capacitypredict_linear on disks warns before it is an outage
Review regularlyDelete or tune the noisiest alerts every month
Watch your backupsAlert on failed jobs; for PostgreSQL see pgBackRest backups

Add a runbook_url annotation and show it in the Slack text. Alerts without a documented response lead to ignored channels. Logs complement metrics: see Loki and Grafana log aggregation. For a comparison of this approach with Zabbix and Nagios, read Zabbix vs Nagios vs HertzBeat.

13. Firewall and SELinux

  • Keep Alertmanager on localhost when Prometheus runs on the same host. If Prometheus is remote, bind to a private address and allow port 9093 only from the Prometheus server with a rich rule (see the firewalld guide). For clustering, also allow TCP and UDP 9094 between peers.
  • SELinux: a binary in /usr/local/bin is labeled bin_t, which systemd can run. Outbound HTTPS to Slack is permitted for ordinary services. If you see denials, check sudo ausearch -m AVC -ts recent and follow the SELinux troubleshooting guide rather than disabling SELinux.
  • Secrets: /etc/alertmanager/slack_webhook_url should be mode 0640, owned by root:alertmanager.

14. Troubleshooting

SymptomLikely causeFix
Rule never firesExpression returns nothing, or for: not elapsedTest the expression in the Prometheus UI; check Alerts for pending state
Alert firing in Prometheus, nothing in Alertmanageralerting section missing or wrong targetCheck prometheus.yml; curl http://127.0.0.1:9093/api/v2/alerts; Prometheus UI Status > Runtime & Build / Alertmanagers
Alert in Alertmanager, no Slack messageWrong webhook, receiver, or routeamtool config routes test ...; read journalctl -u alertmanager for HTTP status errors
invalid_token or no_service from SlackWebhook revoked or wrongCreate a new webhook; update the secret file
channel_not_foundThe channel override is invalid for this webhookRemove channel: or create a webhook for that channel
amtool check-config failsYAML or syntax errors; deprecated fieldsFix indentation; use matchers syntax
Duplicate notificationsMultiple Alertmanagers not clusteredConfigure --cluster.peer; list all instances in Prometheus
Too many messagesGrouping by too many labels, or short repeat_intervalGroup by alertname plus one scope label; raise repeat_interval
Too few messagesOverly broad grouping, inhibition, or a silenceamtool silence query; review inhibit_rules
Resolved messages missingsend_resolved falseSet send_resolved: true
Slack text shows raw {{ }}Template error or wrong fieldTest with a fake alert; check template syntax
Permission denied reading webhook fileWrong ownership or modechown root:alertmanager, chmod 640
Config change not appliedNo reloadsystemctl reload alertmanager
Time-based mute not workingWrong time zone or interval nameVerify location and the interval name in the route
Alerts fire for hosts that are in maintenanceNo silenceCreate a silence before maintenance with amtool
promtool check rules errorsInvalid PromQL or YAMLFix the expression; test in the Prometheus UI

15. FAQ

What is the difference between Prometheus alerts and Alertmanager?
Prometheus evaluates alert rules and decides when an alert fires. Alertmanager handles what happens next: deduplication, grouping, silencing, routing, and sending notifications.

Can Alertmanager send to Slack, email and PagerDuty at once?
Yes. A route can use several receivers through continue: true on routes, or one receiver can contain several integrations, such as slack_configs and email_configs.

How do I stop alerts during maintenance?
Create a silence with amtool silence add or in the Alertmanager UI before you begin, and give it an expiry time.

Where should I keep the Slack webhook?
In a separate file referenced by api_url_file, with strict permissions. Never commit it to Git.

Do I need Grafana for alerting?
No. Prometheus and Alertmanager are enough. Grafana also has its own alerting system, but running rules in Prometheus keeps them in version control next to your configuration.

How do I alert on a certificate or backup that has not run?
Use exporters (blackbox for certificate expiry, a textfile collector or exporter for backup jobs) and alert on stale timestamps, such as time since the last successful backup.

Does Alertmanager store alert history?
Not long-term. It keeps state for deduplication and silences. Use Grafana, Loki, or a ticketing system for history.

(Visited 20 times, 5 visits today)

You may also like