Skip to main content
This walkthrough demonstrates creating Prometheus alerting rules and configuring Alertmanager to route notifications to Slack. The demo assumes Prometheus and Alertmanager are installed and running on the same host (they can run on separate hosts in production).

Verify Alertmanager is running

Check Alertmanager’s systemd status:
Example output:

Create Prometheus alerting rules

Create /etc/prometheus/rules.yaml and define your alert groups. Below is a minimal example for detecting a node being down:
Full example with three alerts (node plus two database jobs). Save as /etc/prometheus/rules.yaml:
Rule labels are critical: they enable Alertmanager to match, group, and route alerts. Use annotations for human-readable alert text and details.
Important rule fields (quick reference): After saving rules, restart Prometheus:
Open the Prometheus web UI and check the Alerts page to confirm the rules loaded:
The image shows a Prometheus web interface open in a Firefox browser, with fields for entering and executing expressions, but no data queried yet. The interface is displayed on a Linux desktop environment.
If Prometheus does not see your rules, ensure your prometheus.yml includes the rule_files entry and your scrape targets. Example /etc/prometheus/prometheus.yml:
Restart Prometheus if you edit this file:
When rules are loaded but not triggered, the Alerts page will show them as inactive (green). When conditions are true, alerts move to Pending and then Firing based on for.

Triggering alerts and how for works

Prometheus evaluates alert expressions on its schedule. Alerts follow this lifecycle:
  • Pending: expression is true but for duration not yet reached.
  • Firing: expression remained true for the full for duration.
Example showing a longer for delay:
With for: 0m alerts become firing immediately. With for: 1m or higher, Prometheus waits before transitioning to firing.

Configure Prometheus to send alerts to Alertmanager

Tell Prometheus where Alertmanager is by adding an alerting section to /etc/prometheus/prometheus.yml:
Restart Prometheus:
Open Alertmanager at http://localhost:9093. You should begin to see alerts arrive there:
The image shows a web interface of Prometheus Alertmanager running in Firefox on a Linux system, displaying alerts for a database being down.
By default, Alertmanager groups by alertname and sends to the default receiver. To group or route alerts differently (for example by team and env), edit Alertmanager’s config at /etc/alertmanager/alertmanager.yml.

Alertmanager routing and Slack receiver

This example Alertmanager configuration:
  • Matches alerts from specific jobs using match_re,
  • Groups alerts by team and env,
  • Sends notifications to a Slack webhook receiver.
Edit /etc/alertmanager/alertmanager.yml:
Routing configuration quick reference: Key notes:
  • match_re selects alerts by label using regular expressions.
  • group_by: ['team', 'env'] bundles alerts that share those label values into a single message.
  • Slack receiver templates use .GroupLabels for group-level info and iterate over .Alerts to include each alert’s .Annotations.message.
Grouping by labels such as team and env reduces notification noise by bundling related alerts into one message per label combination.
Restart Alertmanager after saving the config:
Refresh the Alertmanager UI — alerts should now be grouped by team and env. Expand groups to see individual alerts and annotations:
The image shows the Alertmanager interface displaying two alerts related to a database environment being down, accessible via a web browser on a Linux system.

Verify Slack notifications

If the Slack webhook and channel are configured correctly, Alertmanager will post grouped messages to the specified Slack channel. Example formatted messages for this demo:
You should see the Slack channel showing these notifications:
The image shows a Slack workspace channel titled "#alerts" with messages indicating server downtime alerts for different environments. The sidebar lists channels and options for managing Slack activities.
  • The same routing/grouping concepts apply to other integrations such as PagerDuty or Microsoft Teams; replace slack_configs with the appropriate receiver config.
  • Validate Alertmanager config before deploying changes; for complex templates test in a staging environment first.
  • Use labels consistently across rules and targets (e.g., team, env, job) to simplify grouping and routing.
Helpful references:

Watch Video