Prometheus 监控方案学习笔记(四):Alertmanager 的安装和配置
huty
2022年12月01日 · 阅读 1,554
安装 Alertmanager
Docker Compose 方式
- 目录准备
mkdir -pv /apps/alertmanager/{conf,template}
- 编辑 docker-compose.yml 文件
vim /apps/alertmanager/docker-compose.yml
version: "3"
services:
alertmanager:
image: prom/alertmanager:v0.24.0
container_name: prometheus-alertmanager
hostname: alertmanager
restart: always
volumes:
- /apps/alertmanager/template:/etc/alertmanager/template
- /apps/alertmanager/conf/alertmanager.yml:/etc/alertmanager/alertmanager.yml
ports:
- 9093:9093
networks:
default:
external:
name: prometheus
- 编辑 alertmanager.yml 文件
vim /apps/alertmanager/conf/alertmanager.yml
global:
resolve_timeout: 5m
route:
group_by: ['instance']
group_wait: 30s
group_interval: 30s
repeat_interval: 1h
receiver: 'dingtalk'
routes:
- receiver: 'message'
continue: true
match:
severity: emergency
- receiver: 'dingtalk'
continue: true
match_re:
severity: critical|warning
receivers:
- name: 'dingtalk'
webhook_configs:
- url: 'http://127.0.0.1:9080/prometheusalert?type=dd&tpl=prometheus-dd-my&ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxx'
- name: 'message'
webhook_configs:
- url: 'http://127.0.0.1:9080/prometheusalert?type=txdx&tpl=prometheus-dx-my&phone=xxx'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['instance']
说明:
- 配置文件中
receivers
配置实际的告警发送方式,此处使用了开源组件Prometheus Alert
具体配置请参考官方文档 Alertmanager
官方文档:https://prometheus.io/docs/alerting/latest/alertmanagerPrometheus Alert
官方文档:https://feiyu563.gitbook.io/prometheusalertAlertmanager
配置文件官方说明:https://prometheus.io/docs/alerting/latest/configurationAlertmanager
配置文件详解:https://www.cnblogs.com/kebibuluan/p/14928490.html
- 创建 docker 网段 prometheus
检查是否存在 prometheus 网段:
docker network list
若不存在,则创建:
docker network create prometheus --subnet 10.21.22.0/24
- 启动 Alertmanager 容器
cd /apps/alertmanager
docker-compose up -d
- 查看 Alertmanager 容器状态、查看 Alertmanager 容器日志
cd /apps/alertmanager
docker-compose ps
docker-compose logs -f
- 编辑 Prometheus Server 的 prometheus.yml 文件
编辑 Prometheus 的 prometheus.yml 文件,在顶层结构中添加如下内容:
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
- 重启 Prometheus Server
重启 Prometheus Server 服务
分类:
Prometheus 监控体系
标签:
Prometheus
评论已关闭