menu 学习笔记
search self_improvement
目录

Prometheus 监控方案学习笔记(四):Alertmanager 的安装和配置

huty
huty 2022年12月01日  ·  阅读 1,554

安装 Alertmanager

Docker Compose 方式

  1. 目录准备
mkdir -pv /apps/alertmanager/{conf,template}
  1. 编辑 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
  1. 编辑 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']

说明:

  1. 创建 docker 网段 prometheus
    检查是否存在 prometheus 网段:
docker network list

若不存在,则创建:

docker network create prometheus --subnet 10.21.22.0/24
  1. 启动 Alertmanager 容器
cd /apps/alertmanager
docker-compose up -d
  1. 查看 Alertmanager 容器状态、查看  Alertmanager 容器日志
cd /apps/alertmanager
docker-compose ps
docker-compose logs -f
  1. 编辑 Prometheus Server 的 prometheus.yml 文件
    编辑 Prometheus 的 prometheus.yml 文件,在顶层结构中添加如下内容:
alerting:
  alertmanagers:
  - static_configs:
    - targets: ['localhost:9093']
  1. 重启 Prometheus Server
    重启 Prometheus Server 服务

评论已关闭