This is really old and unmaintained article. If you see any mistakes and outdated content, please contact me, the email is in the footer of the site
For this post I will assume that you already have Prometheus 2.0 installed.
If not, follow one of these two tutorials:
Create a separate user that will be used to run this application:
sudo adduser --no-create-home --disabled-login --shell /bin/false --gecos "Alertmanager User" alertmanager
Next thing you have to do is to create necessary directories and dummy configuration files:
sudo mkdir /etc/alertmanager sudo mkdir /etc/alertmanager/template sudo mkdir -p /var/lib/alertmanager/data sudo touch /etc/alertmanager/alertmanager.yml
/etc/alertmanager will be used to store configuration (
aletmanager.yml) and template (locate in
template/) files. Data generated by the alertmanager will be stored
/var/lib/alertmanager. The rationale to store data in that folder is explained here and here. Look at the
/var/lib section for explanation (tl;dr UNIX standard).
Now that the directories are created, we have to change their ownership, so that the
alertmanager user could use them:
sudo chown -R alertmanager:alertmanager /etc/alertmanager sudo chown -R alertmanager:alertmanager /var/lib/alertmanager
wget https://github.com/prometheus/alertmanager/releases/download/v0.12.0/alertmanager-0.12.0.linux-amd64.tar.gz tar xvzf alertmanager-0.12.0.linux-amd64.tar.gz
Copy utilities to appropriate places in the filesystem:
sudo cp alertmanager-0.12.0.linux-amd64/alertmanager /usr/local/bin/ sudo cp alertmanager-0.12.0.linux-amd64/amtool /usr/local/bin/
And make sure that
alertmanager user owns them:
sudo chown alertmanager:alertmanager /usr/local/bin/alertmanager sudo chown alertmanager:alertmanager /usr/local/bin/amtool
Next, we will add some very generic configuration:
sudo nano /etc/alertmanager/alertmanager.yml
Add this to your configuration file:
global: smtp_smarthost: 'localhost:25' smtp_from: 'email@example.com' smtp_auth_username: 'alertmanager' smtp_auth_password: 'password' templates: - '/etc/alertmanager/template/*.tmpl' route: repeat_interval: 3h receiver: team-X-mails receivers: - name: 'team-X-mails' email_configs: - to: 'team-Xfirstname.lastname@example.org'
At this point I will assume that you know how to configure the alertmanager yaml file. The simple example file should be enough to get you started with the simplest use case (sending mail notification through third party smtp such as smtp.gmail.com). If you are using the alertmanager for small home project, or think that self-hosted mail servers or third party servers are an overkill, you can configure the alertmanager to notify you using your personal gmail (see here).
Next thing we have to do is to setup alertmanager as systemd unit:
sudo nano /etc/systemd/system/alertmanager.service
Copy and paste this into the editor:
[Unit] Description=Prometheus Alertmanager Service Wants=network-online.target After=network.target [Service] User=alertmanager Group=alertmanager Type=simple ExecStart=/usr/local/bin/alertmanager \ --config.file /etc/alertmanager/alertmanager.yml \ --storage.path /var/lib/alertmanager/data Restart=always [Install] WantedBy=multi-user.target
After that, reload daemons, enable alertmanager service on startup, and restart it.
sudo systemctl daemon-reload sudo systemctl enable alertmanager sudo systemctl start alertmanager
Don’t forget to clean up after yourself:
rm alertmanager-0.12.0.linux-amd64.tar.gz rm -rf alertmanager-0.12.0.linux-amd64
And that’s it. The only thing we have to do is to edit the prometheus configuration file so it could be aware of the alertmanager. Add this to the
alerting: alertmanagers: - static_configs: - targets: - localhost:9093
Whew… the only thing you have to do now is to (learn to) write the rules. Good luck! ;)