Skip to content

Instantly share code, notes, and snippets.

@rodrigo-galba
Last active June 14, 2021 14:41
Show Gist options
  • Save rodrigo-galba/cfdc88d31440d627a82328f9ccb9cfb6 to your computer and use it in GitHub Desktop.
Save rodrigo-galba/cfdc88d31440d627a82328f9ccb9cfb6 to your computer and use it in GitHub Desktop.
Alert manager cluster mode

Alert manager cluster mode

Given 2 servers,

1 - Configure the Two Alertmanager Instances to Form a Cluster

  1. On both servers, edit the Alertmanager unit file:
sudo vi /etc/systemd/system/alertmanager.service
  1. In the ExecStart section of the Prometheus Server, add the private IP address of the Alertmanager 2 server using the cluster.peer flag:
    ExecStart=/usr/local/bin/alertmanager \
      --config.file /etc/alertmanager/alertmanager.yml \
      --storage.path /var/lib/alertmanager/ \
      --cluster.peer=10.0.1.102:9094

Note: When you add the cluster.peer line, be sure to add the \ at the end of the storage.path line.

  1. Save and exit the file by pressing Escape followed by :x!.

  2. SSH to AlertManager 2 server with:

ssh 10.0.1.102
  1. In the ExecStart section of the Alertmanager 2 server, add the private IP address of the Prometheus Server using the cluster.peer flag:
$ sudo vi /etc/systemd/system/alertmanager.service

    ExecStart=/usr/local/bin/alertmanager \
      --config.file /etc/alertmanager/alertmanager.yml \
      --storage.path /var/lib/alertmanager/ \
      --cluster.peer=10.0.1.101:9094

Note: When you add the cluster.peer line, be sure to add the \ at the end of the storage.path line.

  1. Save and exit the file by pressing Escape followed by :x!.

  2. On both servers, reload the unit file:

sudo systemctl daemon-reload
  1. On the Prometheus Server, restart Alertmanager:
sudo systemctl restart alertmanager
  1. On the Alertmanager 2 server, enable and start Alertmanager:
sudo systemctl enable alertmanager
sudo systemctl start alertmanager
  1. On both servers, check the status of Alertmanager:
sudo systemctl status alertmanager
  1. They should both show a status of active (running).

  2. On both servers, press Ctrl+C to exit the process.

  3. Access the AlertManager on Prometheus Server instance in a new browser tab: http://<PROMETHEUS_SERVER_PUBLIC_IP>:9093

  4. Click Silences.

  5. Click New Silence.

  6. Set the following values:

    • Name: test
    • Value: 1
    • Creator: me
    • Comment: This is a test
  7. Click Create.

  8. Access the Alertmanager 2 instance in a new browser tab: http://<ALERTMANAGER_2_PUBLIC_IP>:9093

  9. Click Silences, and verify the silence you created on the Prometheus Server instance appears.

  10. Click View, and we should then see it's the one we created.

2 - Configure Prometheus to Use Your Multi-Instance Alertmanager Setup

  1. Close out of the Alertmanager 2 terminal, as we will no longer be working in it.

  2. On the Prometheus Server, edit the Prometheus configuration file:

sudo vi /etc/prometheus/prometheus.yml
  1. Add the new Alertmanager (10.0.1.102:9093) to the list of Alertmanager targets:
alerting:
    alertmanagers:
    - static_configs:
    - targets:
        - localhost:9093
        - 10.0.1.102:9093
  1. Save and exit the file by pressing Escape followed by :x!.

  2. Restart Prometheus to reload the config:

sudo systemctl restart prometheus
  1. Access the Prometheus server in the browser: http://<PROMETHEUS_SERVER_PUBLIC_IP>:9090

  2. Click Status > Runtime & Build Information.

  3. Verify both of your Alertmanagers appear under the Alertmanagers section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment