AlertManager is a component of the Prometheus ecosystem that handles alerts sent by Prometheus server. Its primary responsibility is to deduplicate, group, and route alerts to the appropriate recipient integration such as email, Slack, or other notification channels. In our project, AlertManager is configured to send email notifications when specific monitoring thresholds are breached.
Our AlertManager instance is configured in Docker Compose as follows:
alertmanager:
<<: *common
build:
context: ./src/grafana
dockerfile: Dockerfile.alertmanager
profiles: ["grafanaprofile"]
container_name: alertmanager
environment:
- EMAIL_FROM=${EMAIL_FROM}
- EMAIL_TO=${EMAIL_TO}
- EMAIL_HOST=${EMAIL_HOST}
- EMAIL_PORT=${EMAIL_PORT}
- EMAIL_HOST_USER=${EMAIL_HOST_USER}
- EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD}
ports:
- "9093:9093"
logging:
driver: gelf
options:
gelf-address: "udp://${LOG_HOST}:12201"
tag: "alertmanager"
Our AlertManager is configured with email notifications:
global:
resolve_timeout: 1m
smtp_smarthost: '${EMAIL_HOST}:${EMAIL_PORT}'
smtp_from: '${EMAIL_FROM}'
smtp_auth_username: '${EMAIL_HOST_USER}'
smtp_auth_password: '${EMAIL_HOST_PASSWORD}'
smtp_require_tls: true
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 5m
repeat_interval: 3h
receiver: 'email-notifications'
receivers:
- name: 'email-notifications'
email_configs:
- to: '${EMAIL_TO}'
from: '${EMAIL_FROM}'
send_resolved: true
headers:
subject: ''
html: ''
resolve_timeout
: How long to wait before resolving an alert (1 minute)smtp_smarthost
: The SMTP server used for sending emailssmtp_from
: The sender email addresssmtp_auth_username
: Username for SMTP authenticationsmtp_auth_password
: Password for SMTP authenticationsmtp_require_tls
: Forces TLS for secure email transmissiongroup_by
: Groups alerts by alert namegroup_wait
: Initial wait time before sending a notification for a new group (10s)group_interval
: Minimum time between sending two notifications for a group (5m)repeat_interval
: Minimum time before resending an alert (3h)receiver
: Default receiver for all alertssend_resolved: true
ensures notifications when alerts are resolvedOur AlertManager uses the following environment variables for configuration:
EMAIL_FROM
: Sender email addressEMAIL_TO
: Recipient email address(es)EMAIL_HOST
: SMTP server hostnameEMAIL_PORT
: SMTP server port (typically 587 for TLS)EMAIL_HOST_USER
: SMTP authentication usernameEMAIL_HOST_PASSWORD
: SMTP authentication passwordThese variables are set in the .env file or passed through CI/CD secrets for security.
AlertManager uses Go templates for email formatting. The default templates provide:
The send_resolved: true
setting ensures that:
When set to false
(default), only firing alerts trigger notifications.
To verify AlertManager is working correctly:
telnet ${EMAIL_HOST} ${EMAIL_PORT}
docker logs alertmanager
http://localhost:9093
smtp_require_tls: false
for testinggroup_by
settings to control how alerts are groupedgroup_wait
and group_interval
to change notification timingThe AlertManager web interface is accessible at:
http://localhost:9093
Key pages:
Prometheus is configured to send alerts to AlertManager through the alerting
section in its configuration:
alerting:
alertmanagers:
- static_configs:
- targets: ['alertmanager:9093']