|
# Follwing Code you Add in alert.yaml |
|
========================================================================= |
|
groups: |
|
- name: custom_rules |
|
rules: |
|
- alert: DiskSpaceFree10Percent |
|
expr: node_filesystem_avail_bytes{mountpoint="/", fstype="xfs"} <= 6519140359 |
|
labels: |
|
severity: warning |
|
annotations: |
|
summary: "Instance [{{ $labels.instance }}] has 10% or less Free disk space" |
|
description: "[{{ $labels.instance }}] has only {{ $value }}% or less free." |
|
========================================================================= |
|
# Follwing Code you Add in prometheus.yml |
|
========================================================================= |
|
# Alertmanager configuration |
|
alerting: |
|
alertmanagers: |
|
- static_configs: |
|
- targets: |
|
- 3.110.33.54:9093 |
|
|
|
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. |
|
rule_files: |
|
# - "first_rules.yml" |
|
# - "second_rules.yml" |
|
- "prometheus_rules.yml" |
|
- "alert.yaml" |
|
========================================================================= |
|
|
|
========================================================================= |
|
Step 1 - Download and Install Prometheus Alert Manager |
|
========================================================================= |
|
wget https://github.com/prometheus/alertmanager/releases/download/v0.19.0/alertmanager-0.19.0.linux-amd64.tar.gz |
|
tar xvfz alertmanager-0.19.0.linux-amd64.tar.gz |
|
cd alertmanager-0.19.0.linux-amd64 |
|
ls -lh |
|
========================================================================= |
|
Step 2 - Run Prometheus Alert Manager without service |
|
========================================================================= |
|
./alertmanager --config.file=alertmanager.yml |
|
# Note that it's running on port 9093 |
|
|
|
========================================================================= |
|
Step 3 - Run Prometheus Alert Manager with service |
|
========================================================================= |
|
# Stop existing runing Prometheus Alert Manager |
|
$ cp -r . /usr/local/bin/alertmanager |
|
$ sudo vi /etc/systemd/system/alertmanager.service |
|
|
|
------------------------------------------------- |
|
[Unit] |
|
Description=Prometheus Alert Manager Service |
|
After=network.target |
|
|
|
[Service] |
|
Type=simple |
|
ExecStart=/usr/local/bin/alertmanager/alertmanager \ |
|
--config.file=/usr/local/bin/alertmanager/alertmanager.yml \ |
|
--web.external-url=https://[your domain name]/alertmanager \ |
|
--web.route-prefix=/ |
|
|
|
[Install] |
|
WantedBy=multi-user.target |
|
========================================================================= |
|
Step 4 - Now start and check the service is running. |
|
========================================================================= |
|
$ sudo service alertmanager start |
|
$ sudo service alertmanager status |
|
$ sudo service alertmanager stop |
|
|
|
========================================================================= |
|
Step 5 - How to access Prometheus Alert Manager |
|
========================================================================= |
|
Try http://[your domain name]:9093/ |
|
|
|
========================================================================= |
|
Step 6 - Install and Configure "Send Only SMTP Server" in REHL or Ubuntu? |
|
========================================================================= |
|
RHEL/CENTOS |
|
--------------- |
|
|
|
Ubuntu |
|
--------------- |
|
sudo apt install mailutils |
|
sudo vi /etc/postfix/main.cf |
|
# scroll to the bottom, and set |
|
inet_interfaces = loopback-only |
|
inet_protocols = ipv4 |
|
# restart postfix |
|
sudo systemctl restart postfix |
|
# try sending an email from the command line, |
|
echo "This is the body" | mail -s "This is the subject" -a "FROM:[senders address]" [your personal email] |
|
|
|
========================================================================= |
|
Step 7 - Configure Alert Manager to Send Alerts from Prometheus |
|
========================================================================= |
|
We now configure the Prometheus and Alert Manager processes to communicate with each other, and to send alerts when the alerting |
|
|
|
rules fire. |
|
|
|
# Edit Alert Manager Configuration |
|
$ sudo vi /usr/local/bin/alertmanager/alertmanager.yml |
|
--------------------- |
|
route: |
|
group_by: ['alertname'] |
|
receiver: smtp-local |
|
receivers: |
|
- name: 'smtp-local' |
|
email_configs: |
|
- to: 'your email address' |
|
from: 'your email from address' |
|
require_tls: false |
|
smarthost: localhost:25 |
|
send_resolved: true |
|
----------------------------- |
|
|
|
# Check your configuration with the supplied amtool |
|
/usr/local/bin/alertmanager/amtool check-config /usr/local/bin/alertmanager/alertmanager.yml |
|
|
|
# If all is ok, restart the Alert Manager service. |
|
sudo service alertmanager restart |
|
sudo service alertmanager status |
|
========================================================================= |
|
Step 8 - Edit Prometheus Configuration |
|
========================================================================= |
|
Open the prometheus.yml configuration file and add the text below to the alerting section |
|
$ sudo vi /usr/local/bin/prometheus/prometheus.yml |
|
|
|
# Add - localhost:9093 to your Alertmanager configuration section |
|
|
|
alerting: |
|
alertmanagers: |
|
- static_configs: |
|
- targets: |
|
# alertmanager:9093 |
|
- localhost:9093 |
|
|
|
# Check the prometheus configuration with the supplied promtool. |
|
/usr/local/bin/prometheus/promtool check config /usr/local/bin/prometheus/prometheus.yml |
|
sudo service prometheus restart |
|
sudo service prometheus status |
|
========================================================================= |
|
Step 9 - Check the Prometheus UI |
|
========================================================================= |
|
[Status]-->[Runtime and Build Information] |
|
Copy the url in the Alertmanagers section |
|
http://localhost:9093/api/v1/alerts |
|
Test it using curl |