docker-compose.yml:服务已启动并正在运行。
version: '3'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- 9090:9090
volumes:
- ./prometheus/conf:/etc/prometheus
# - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./alertmanager/alert_rules.yml:/alertmanager/alert.rules.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
alertmanager:
image: prom/alertmanager:latest
container_name: alertmanager
ports:
- 9093:9093
volumes:
- ./alertmanager/:/etc/alertmanager/
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
- '--storage.path=/alertmanager'
prometheus.yml:具有目标和警报目标集的Prometheus配置文件。 alertmanager目标网址工作正常。
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
- 10.10.5.14:9093
scheme: http
timeout: 10s
api_version: v1
rule_files:
- "/alertmanager/alert.rules:/alertmanager/alert.rules"
scrape_configs:
- job_name: 'blackbox'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- "google.com"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9115
alert.rules:标准警报规则。
groups:
- name: example
rules:
# Alert for any instance that is unreachable for >1 minutes.
- alert: InstanceDown
expr: up == 0
for: 1m
alertmanager.yml:用于通过gmail smtp发送警报的代码。
route:
group_by: [Alertname]
# Send all notifications to me.
receiver: email-me
receivers:
- name: email-me
email_configs:
- to: anyemail.com
from: senderlogin@gmail.com
smarthost: smtp.gmail.com:587
auth_username: "senderlogin@gmail.com"
auth_identity: "senderlogin@gmail.com"
auth_password: "password"
问题:所有容器都可以使用,但是prometheus规则中没有任何规则。 字母也没有相应地出现。我不明白我错过了什么。欢迎任何提示。谢谢。 enter image description here enter image description here
答案 0 :(得分:0)
从prometheus容器的角度来看,Alertmanager不在本地主机上,网络在容器中命名空间,因此您需要使用DNS发现联系Alertmanager来查找当前容器IP。通过compose,将自动为服务名称配置DNS,在这种情况下为alertmanager
:
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093