[英]How to configure prometheus with alertmanager?
docker-compose.yml:這是運行 prometheus、node-exporter 和 alert-manager 服務的 docker-compose。 所有服務都運行良好。 甚至普羅米修斯的目標菜單中的健康狀況也顯示正常。
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'
普羅米修斯.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
警報管理器.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'
問題:所有容器都工作正常我無法找出確切的問題。我真正想念的是什么。 檢查普羅米修斯中的警報顯示。
警報 未定義警報規則
您的./alertmanager/alert.rules
文件未包含在您的./alertmanager/alert.rules
配置中,因此它在容器中不可用。 您需要將它添加到prometheus服務:
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文檔 。 你的alert.rules
文件應該是這樣的:
groups:
- name: example
rules:
# Alert for any instance that is unreachable for >5 minutes.
- alert: InstanceDown
expr: up == 0
for: 5m
一旦有多個文件,最好將整個目錄添加為卷而不是單個文件。
如果您需要此問題的答案,請參閱此鏈接的解釋How to make alert rules visible on Prometheus User Interface?
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 和 go 到 cd /etc/prometheus
docker exec -it fa99f733f69b sh
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.