Alert Manager
NotesPrometheus decides when an alert fires; Alertmanager decides what happens: who gets notified, how, and how often. It also groups related alerts into one notification, and can silence alerts during maintenance.
Create a directory for its configuration:
mkdir -p ~/volumes/alertmanagerAdd a configuration file. Alertmanager can send notifications by email, Slack, PagerDuty, webhooks and more. Here it sends email, so use the same SMTP settings as the application’s contact form:
global:
smtp_smarthost: 'smtp.example.com:587'
smtp_from: 'Alertmanager <alerts@exampleforyou.net>'
smtp_auth_username: 'USERNAME'
smtp_auth_password: 'PASSWORD'
smtp_require_tls: true
route:
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: admins
receivers:
- name: 'admins'
email_configs:
- to: 'admin@exampleforyou.net'routesends every alert to theadminsreceiver.group_byputs alerts with the same name into one email,group_waitwaits 30 seconds to collect related alerts before the first email, andrepeat_intervalresends every three hours while an alert is still firing.receiverslists who gets notified, and how.
Check the configuration with amtool, which is in the image:
podman run --rm --entrypoint amtool -v ~/volumes/alertmanager:/etc/alertmanager:Z \
docker.io/prom/alertmanager:v0.35.1 check-config /etc/alertmanager/alertmanager.ymlCreate a volume for its data (it remembers silences and which notifications it has sent):
podman volume create alertmanager-volAnd run it:
podman run -d --name alertmanager --network monitoring-network -p 9093:9093 \
-v ~/volumes/alertmanager:/etc/alertmanager:Z \
-v alertmanager-vol:/alertmanager \
docker.io/prom/alertmanager:v0.35.1Alertmanager has a web interface for viewing alerts and creating silences at http://localhost:9093.
Now tell Prometheus where to send alerts, in prometheus.yml, using the container’s name:
alerting:
alertmanagers:
- static_configs:
- targets: ['alertmanager:9093']podman restart prometheusAll being well, any alert that fires in Prometheus now appears in Alertmanager, and if the SMTP settings are right, you’ll receive an email.
Here’s the complete prometheus.yml at this point:
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
environment: dev
rule_files:
- /etc/prometheus/rules/*.yml
alerting:
alertmanagers:
- static_configs:
- targets: ['alertmanager:9093']
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['prometheus:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['host.containers.internal:9100']
- job_name: 'fastapi'
static_configs:
- targets: ['host.containers.internal:8000']