How to Setup Prometheus Alertmanager with Email Alerts on Ubuntu 22.04

Introduction

Prometheus is great for collecting server metrics, but we also need to be notified when something goes wrong.
This is where Alertmanager comes in.
Alertmanager works with Prometheus and sends alerts to email, Slack, or other systems when certain conditions are met.
In this guide, we will set up Prometheus Alertmanager with Email alerts on Ubuntu 22.04.

Concept: How Alerts Work

  1. Prometheus collects metrics from servers (via exporters).
  2. We define alert rules in Prometheus (example: CPU > 80%).
  3. When condition is true, Prometheus sends alert to Alertmanager.
  4. Alertmanager sends notification (email, Slack, etc.).

Step 1: Download and Install Alertmanager

wget https://github.com/prometheus/alertmanager/releases/download/v0.26.0/alertmanager-0.26.0.linux-amd64.tar.gz
tar xvf alertmanager-0.26.0.linux-amd64.tar.gz
cd alertmanager-0.26.0.linux-amd64
sudo cp alertmanager /usr/local/bin/
sudo cp amtool /usr/local/bin/
sudo mkdir /etc/alertmanager /var/lib/alertmanager

Step 2: Configure Alertmanager

Create config file:

sudo nano /etc/alertmanager/alertmanager.yml

Example Email configuration (using Gmail SMTP):

global:
  smtp_smarthost: 'smtp.gmail.com:587'
  smtp_from: 'alerts@bitscentric.local'
  smtp_auth_username: 'yourgmail@gmail.com'
  smtp_auth_password: 'your-app-password'

route:
  receiver: 'email-alert'

receivers:
- name: 'email-alert'
  email_configs:
  - to: 'admin@bitscentric.local'
    send_resolved: true

Note: If using Gmail, you must create an App Password instead of using your normal password.

Step 3: Create Alertmanager Service

sudo nano /etc/systemd/system/alertmanager.service

Add:

[Unit]
Description=Alertmanager
After=network.target

[Service]
ExecStart=/usr/local/bin/alertmanager \
  --config.file=/etc/alertmanager/alertmanager.yml \
  --storage.path=/var/lib/alertmanager
Restart=always

[Install]
WantedBy=multi-user.target

Start service:

sudo systemctl daemon-reload
sudo systemctl enable alertmanager
sudo systemctl start alertmanager

Access UI at: http://server-ip:9093

Step 4: Configure Prometheus to Use Alertmanager

Edit Prometheus config file /etc/prometheus/prometheus.yml:

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

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

Step 5: Create Alert Rules

Create file /etc/prometheus/alert.rules.yml:

groups:
- name: example-alert
  rules:
  - alert: HighCPUUsage
    expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[2m])) * 100) > 80
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: "High CPU usage detected on { $labels.instance }"
      description: "CPU usage is above 80% for more than 2 minutes."

Restart Prometheus:

sudo systemctl restart prometheus

Step 6: Testing Alerts

  • Stop Node Exporter → Prometheus will raise alert → Alertmanager sends email.
  • Generate CPU load (using stress tool) → Alert fires.

Check Prometheus Alerts UI: http://server-ip:9090/alerts

Check Alertmanager UI: http://server-ip:9093

Check Email → You should receive an alert.

Benefits of Alertmanager

  • Immediate notifications for server issues (CPU, memory, disk, etc.).
  • Prevents downtime by alerting before systems crash.
  • Supports multiple channels (Email, Slack, PagerDuty).
  • Flexible rules (severity, grouping, silencing).

Best Practices

  • Use separate email account for alerts.
  • Group alerts to avoid flooding inbox.
  • Integrate with Slack or Teams for better team alerts.
  • Always test rules before production.
  • Secure Alertmanager with firewall or reverse proxy.

Conclusion

We successfully set up Prometheus Alertmanager with Email alerts on Ubuntu 22.04.
Now the system will send alerts when CPU, memory, or disk usage crosses defined thresholds.
This setup is essential for production environments to monitor servers and take quick actions.

Leave a Reply

Your email address will not be published. Required fields are marked *