如何使用警报管理器配置普罗米修斯?
How to configure prometheus with alertmanager?
docker-compose.yml:
这是 docker-compose 到 运行 普罗米修斯、节点导出器和警报管理器服务。所有服务 运行 都很棒。连prometheus的target menu里的health status都显示ok
version: '2'
services:
prometheus:
image: prom/prometheus
privileged: true
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./alertmanger/alert.rules:/alert.rules
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'
node-exporter:
image: prom/node-exporter
ports:
- '9100:9100'
alertmanager:
image: prom/alertmanager
privileged: true
volumes:
- ./alertmanager/alertmanager.yml:/alertmanager.yml
command:
- '--config.file=/alertmanager.yml'
ports:
- '9093:9093'
prometheus.yml
这是包含目标和警报目标集的 prometheus 配置文件。 alertmanager 目标 url 工作正常。
global:
scrape_interval: 5s
external_labels:
monitor: 'my-monitor'
# this is where I have simple alert rules
rule_files:
- ./alertmanager/alert.rules
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
alerting:
alertmanagers:
- static_configs:
- targets: ['some-ip:9093']
alert.rules:
只是一个简单的警报规则,用于在服务中断时显示警报
ALERT service_down
IF up == 0
alertmanager.yml
这是在发生警报时在松弛状态下发送消息。
global:
slack_api_url: 'https://api.slack.com/apps/A90S3Q753'
route:
receiver: 'slack'
receivers:
- name: 'slack'
slack_configs:
- send_resolved: true
username: 'tara gurung'
channel: '#general'
api_url: 'https://hooks.slack.com/services/T52GRFN3F/B90NMV1U2/QKj1pZu3ZVY0QONyI5sfsdf'
问题:
所有的容器都工作正常我无法弄清楚确切的 problem.What 我真的错过了。检查 prometheus 中的警报显示。
提醒
未定义警报规则
您的 ./alertmanager/alert.rules
文件未包含在您的 docker 配置中,因此在容器中不可用。您需要将其添加到普罗米修斯服务中:
prometheus:
image: prom/prometheus
privileged: true
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./alertmanager/alert.rules:/alertmanager/alert.rules
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'
并且可能在prometheus.yml
:
中给出一个绝对路径
rule_files:
- "/alertmanager/alert.rules"
您还需要确保警报规则有效。有关详细信息和示例,请参阅 prometheus docs。您 alert.rules
文件应如下所示:
groups:
- name: example
rules:
# Alert for any instance that is unreachable for >5 minutes.
- alert: InstanceDown
expr: up == 0
for: 5m
如果您有多个文件,最好将整个目录添加为一个卷而不是单个文件。
如果您需要此问题的答案,请参阅此 link 的解释
prometheus.yml 中的警报规则应如下所示
rule_files:
- "/etc/prometheus/alert.rules.yml"
您需要停止 alertmanager 和 prometheus 容器以及 运行 这个
docker run -d --name prometheus_ops -p 9191:9090 -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml -v $(pwd)/alert.rules.yml:/etc/prometheus/alert.rules.yml prom/prometheus
验证您是否可以看到 alert.rule 配置路径:Prometheus 容器 ID 并转到 cd /etc/prometheus
docker exec -it fa99f733f69b sh
docker-compose.yml: 这是 docker-compose 到 运行 普罗米修斯、节点导出器和警报管理器服务。所有服务 运行 都很棒。连prometheus的target menu里的health status都显示ok
version: '2'
services:
prometheus:
image: prom/prometheus
privileged: true
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./alertmanger/alert.rules:/alert.rules
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'
node-exporter:
image: prom/node-exporter
ports:
- '9100:9100'
alertmanager:
image: prom/alertmanager
privileged: true
volumes:
- ./alertmanager/alertmanager.yml:/alertmanager.yml
command:
- '--config.file=/alertmanager.yml'
ports:
- '9093:9093'
prometheus.yml
这是包含目标和警报目标集的 prometheus 配置文件。 alertmanager 目标 url 工作正常。
global:
scrape_interval: 5s
external_labels:
monitor: 'my-monitor'
# this is where I have simple alert rules
rule_files:
- ./alertmanager/alert.rules
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
alerting:
alertmanagers:
- static_configs:
- targets: ['some-ip:9093']
alert.rules: 只是一个简单的警报规则,用于在服务中断时显示警报
ALERT service_down
IF up == 0
alertmanager.yml
这是在发生警报时在松弛状态下发送消息。
global:
slack_api_url: 'https://api.slack.com/apps/A90S3Q753'
route:
receiver: 'slack'
receivers:
- name: 'slack'
slack_configs:
- send_resolved: true
username: 'tara gurung'
channel: '#general'
api_url: 'https://hooks.slack.com/services/T52GRFN3F/B90NMV1U2/QKj1pZu3ZVY0QONyI5sfsdf'
问题: 所有的容器都工作正常我无法弄清楚确切的 problem.What 我真的错过了。检查 prometheus 中的警报显示。
提醒 未定义警报规则
您的 ./alertmanager/alert.rules
文件未包含在您的 docker 配置中,因此在容器中不可用。您需要将其添加到普罗米修斯服务中:
prometheus:
image: prom/prometheus
privileged: true
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./alertmanager/alert.rules:/alertmanager/alert.rules
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'
并且可能在prometheus.yml
:
rule_files:
- "/alertmanager/alert.rules"
您还需要确保警报规则有效。有关详细信息和示例,请参阅 prometheus docs。您 alert.rules
文件应如下所示:
groups:
- name: example
rules:
# Alert for any instance that is unreachable for >5 minutes.
- alert: InstanceDown
expr: up == 0
for: 5m
如果您有多个文件,最好将整个目录添加为一个卷而不是单个文件。
如果您需要此问题的答案,请参阅此 link 的解释
prometheus.yml 中的警报规则应如下所示
rule_files:
- "/etc/prometheus/alert.rules.yml"
您需要停止 alertmanager 和 prometheus 容器以及 运行 这个
docker run -d --name prometheus_ops -p 9191:9090 -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml -v $(pwd)/alert.rules.yml:/etc/prometheus/alert.rules.yml prom/prometheus
验证您是否可以看到 alert.rule 配置路径:Prometheus 容器 ID 并转到 cd /etc/prometheus
docker exec -it fa99f733f69b sh