基础环境

1.Prometheus 版本:2.22.2

下载地址:

https://github.com/prometheus/prometheus/releases/download/v2.22.2/prometheus-2.22.2.linux-amd64.tar.gz

2.Alertmanager 版本:0.23

下载地址:

https://github.com/prometheus/alertmanager/releases/download/v0.23.0/alertmanager-0.23.0.linux-amd64.tar.gz

3.prometheus-webhook-dingtalk :1.4

下载地址:

https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v1.4.0/prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz

1.新增用户和用户组

➜ groupadd prometheus
➜ useradd -g prometheus -M -s /sbin/nologin prometheus

2.安装配置 Prometheus Server

详细 Prometheus 安装流程请参考:https://mp.weixin.qq.com/s/BcKN4s7qDokG_YmXn8Q-zQ需要确保服务启动完成后,可以正常访问:http://localhost:9090,且 Doris 的 metrics 已经打入 Prometheus 中。

3.安装 AlertManager 模块

3.1 下载安装包

➜ wget https://github.com/prometheus/alertmanager/releases/download/v0.23.0/alertmanager-0.23.0.linux-amd64.tar.gz
➜ tar xf alertmanager-0.23.0.linux-amd64.tar.gz -C /soft
➜ cd /soft
➜ mv alertmanager-0.23.0.linux-amd64 alertmanager
➜ cd alertmanager
➜ mkdir data #系统文件持久化路径
➜ chown -R prometheus.prometheus /soft/alertmanager

说明:创建 data 目录是必须要操作的,不然后期启动 alertmanager 会异常。

3.2 配置 alertmanager.yml 文

route:
group_by: ['alertname']
group_wait: 1s
group_interval: 1m
repeat_interval: 4h
receiver: 'webhook2'
receivers:
- name: 'webhook2'
webhook_configs:
- &dingtalk_config
send_resolved: true
url: http://localhost:8060/dingtalk/webhook2/send
#An inhibition rule mutes an alert (target) matching a set of matchers when an alert (source) exists that matches another set of matchers. Both target and source alerts must have the same label values for the label names in the equal list.
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']

名词解释:

  • group_wait :设置等待时间,如果在等待时间内当前 Group 接收到了新的告警,这些告警将会合并为一个通知向 Receiver 发送。
  • group_interval :用于定义相同的 Group 之间发送告警通知的时间间隔。
  • repeat_interval:用于表示当一个规则成功被发送,重复发送报警的第二次间隔时间。

3.3 检查配置文件配置

很重要,关乎程序能否正常启动。当出现如下图片时,说明 alertmanager.yml 文件配置正常。

➜ cd /soft/alertmanager
➜ ./amtool check-config ./alertmanager.yml

3.4 创建 Alertmanager 系统服务启动文件

➜ vim /usr/lib/systemd/system/alertmanager.service

[Unit]
Description=alertmanager
Documentation=https://prometheus.io/
After=network.target [Service]
User=prometheus
Group=prometheus
ExecStart=/soft/alertmanager/alertmanager --config.file=/soft/alertmanager/alertmanager.yml --storage.path=/soft/alertmanager/data
Restart=on-failure [Install]
WantedBy=multi-user.target

3.5 启动服务

systemctl daemon-reload
systemctl enable alertmanager.service
systemctl start alertmanager.service
systemctl status alertmanager.service #查看服务状态
systemctl restart alertmanager.service #重启服务使用

3.6 启动服务后

服务启动后,可以在http://localhost:9093查看ui界面

3.7 在 Prometheus 中配置 Alertmanager 模块需要在 Prometheus 的安装目录下的 prometheus.yml 文件中加入 Alertmanager 通信地址和端口号,同时配置 alert rules 目录,该目录主要存放配置的报警规则。

vim prometheus.yml 

alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093'] #根据实际alertmanager服务地址配置。 rule_files:
- "rule/*.yml" #自定义规则存储目录,可以通过*.yml来通配该目录下所有规则。

3.8 重新加载 Prometheus 配置文件,查看 alerting 配置是否生效

Prometheus 服务支持热加载。当配置文件发生改变时,可以通过以下命令重新加载配置文件:

➜ ./promtool check config  prometheus.yml
➜ systemctl reload prometheus.service

重启成功后,可以通过:http://localhost:9090/config查看 alerting 配置是否生效。

4.安装 prometheus-webhook-dingtalk 插件

4.1 下载插件

➜ wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v1.4.0/prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
➜ tar -xf prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz -C /soft
➜ mv prometheus-webhook-dingtalk-1.4.0.linux-amd64 prometheus-webhook-dingtalk

4.2 在钉钉群配置机器人配置机器人时,需要添加自定义关键词,这个关键词后期在配置规则报警信息时,也同样需要出现,不然无法发送报警。

4.3 修该配置文件在 webhook2 中配置刚才申请的机器人的地址,需要注意的是你的机器人路径配置在哪,那么 alertmanager.yml 中的 url 路径也要随之改变。

➜ cp  config.example.yml  config.yml

## Request timeout
# timeout: 5s ## Customizable templates path 自定义模板位置
templates:
- /soft/alertmanager/alarm_template/webhook.tmpl
## You can also override default template using `default_message`
## The following example to use the 'legacy' template from v0.3.0
# default_message:
# title: '{{ template "legacy.title" . }}'
# text: '{{ template "legacy.content" . }}' ## Targets, previously was known as "profiles"
targets:
webhook1: #加签的钉钉,需要同时配置加签机器人的密钥信息
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
# secret for signature
secret: SEC000000000000000000000
webhook2: #不加签钉钉
url: https://oapi.dingtalk.com/robot/send?access_token=cf9c2fd69723661108b7fd7******
webhook_legacy:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
# Customize template content
message:
# Use legacy template
title: '{{ template "legacy.title" . }}'
text: '{{ template "legacy.content" . }}'
webhook_mention_all: #@所有人钉钉
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
mention:
all: true
webhook_mention_users: #@指定用户钉钉
url: https://oapi.dingtalk.com/robot/send?access_token=cf9c2fd69723661108b7fd7****
mention:
mobiles: ['152****30', '134****74']

4.4 创建 webhook-dingtalk 系统服务启动文件

vim /usr/lib/systemd/system/webhook-dingtalk.service

[Unit]

[Unit]
Description=prometheus-webhook-dingtalk
Documentation=https://github.com/timonwong/prometheus-webhook-dingtalk
After=network.target [Service]
User=prometheus
Group=prometheus
ExecStart=/soft/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk --config.file=/soft/prometheus-webhook-dingtalk/config.yml
Restart=on-failure [Install]
WantedBy=multi-user.target

4.5 启动服务

systemctl daemon-reload
systemctl enable webhook-dingtalk.service
systemctl start webhook-dingtalk.service
systemctl status webhook-dingtalk.service
systemctl restart webhook-dingtalk.service

4.6 查看 webhook-dingtalk 服务状态

5.配置报警规则

在 Prometheus 安装目录下的 prometheus.yml 文件中查看“rule_files”对应配置的目录地址,在该目录下新建报警规则。如果不清楚规则如何配置,可以在你安装的 Prometheus 的 UI 地址:http://localhost:9090/graph下查看 metrics 信息。example:

5.1 配置 Doris fe 和 be 报警规则当 Doris instance 是正常状态时,up ==1;当instance down机后,up ==0注意:配置报警规则时,报警机器人自定义的关键字,在配置规则文件的 description 中必须要出现,不然钉钉群无法接收到报警信息。

➜ vim doris_instance.yml

groups:
- name: doris_instance_down
rules:
- alert: Doris Backends Down
expr: up {group="be", job="pro-doris"} == 0
for: 20s
labels:
user: doris
severity: error
annotations:
summary: "doris Instance {{ $labels.instance }} down"
description: "doris {{ $labels.instance }} of job {{ $labels.job }} has been down for more than 20s."
- alert: Doris Frontends Down
expr: up {group="fe", job="pro-doris"} == 0
for: 20s
labels:
user: doris
severity: error
annotations:
summary: "doris Instance {{ $labels.instance }} down"
description: "doris {{ $labels.instance }} of job {{ $labels.job }} has been down for more than 20s."

5.2 校验规则文件如果是规则文件是 “SUCCESS” 状态,则说明规则文件配置正确,否则则需要检查配置对应的配置文件。

➜ cd /soft/prometheus
➜ ./promtool check config prometheus.yml

5.3 重新加载 Prometheus 配置文件

➜ systemctl reload prometheus.service

6.测试

当 Doris 集群中的 instance 出现 down 机后,钉钉群里新建的机器人会发出报警信息。

当在 alertmanager.yml 文件中配置了 send_resolved = true,异常解除同样会发送钉钉警告信息,否则则不发送。

至此,Prometheus 监控 Doris 异常信息并发送报警至钉钉流程结束

使用 Prometheus Alertmanager 模块发送 Doris 异常信息至钉钉报警群的更多相关文章

  1. Prometheus alertmanager邮件发送+grafana告警展示

    前言 前面一篇博客,我已经介绍了prometheus如何监控mysql. 这一篇我来介绍如何通过alertmanger进行告警邮件发送(微信或钉钉类似,因为需要企业帐户,我就不试了),以及如何通过gr ...

  2. 验证Prometheus alertmanager邮件发送

    新环境上配置alertmanager时出现了“Client was not authenticated to send anonymous mail during MAIL FROM”错误,但老环境上 ...

  3. 通过GSM模块发送经纬度求救信息。

    本博客作为实验笔记,仅供学习交流.(转载请注明出处) 本实验通过GSM模块:SIM900a,实现向特定手机发送sos求救信号,并且利用GPS模块:微科VK2828U7G5LF,将经纬度信息同时发送到手 ...

  4. PHP 错误与异常 笔记与总结(14 )记录和发送异常信息

    当发生异常时,把异常信息记录到日志文件中: <?php header('content-type:text/html; charset=utf-8'); class LogException e ...

  5. Prometheus + Alertmanager 实现企微告警

    上一篇:二进制安装Prometheus  下面准备在监控的流程中呈现到告警到企微 查看企业ID,用于后续配置文件 四.安装Alertmanager1.准备安装的包 --选择上面链接给的Linux的ta ...

  6. Longhorn,企业级云原生容器分布式存储 - 监控(Prometheus+AlertManager+Grafana)

    内容来源于官方 Longhorn 1.1.2 英文技术手册. 系列 Longhorn 是什么? Longhorn 企业级云原生容器分布式存储解决方案设计架构和概念 Longhorn 企业级云原生容器分 ...

  7. [置顶] 个人微信号发送zabbix告警信息

    之前使用邮件和短信发送zabbix告警信息,但告警信息无法实时查看或者无法发送,故障无法及时通知运维人员. 后来使用第三方微信接口发送信息,愉快地用了一年多,突然收费了. zabbix告警一直是我的痛 ...

  8. prometheus学习系列十: Prometheus AlertManager配置文件说明

    alertmanager配置文件说明 alertmanager是通过命令行标记和配置文件配置的,命令行标记配置不可变的系统参数,配置文件定义抑制规则.通知路由和通知接收器.可以通过官方提供的routi ...

  9. prometheus学习系列九: Prometheus AlertManager使用

    在Prometheus的报警系统中,是分为2个部分的, 规则是配置是在prometheus中的, prometheus组件完成报警推送给alertmanager的, alertmanager然后管理这 ...

随机推荐

  1. markdown类型文件编辑大全

    正文: 1.标题的几种写法: 第一种:     前面带#号,后面带文字,分别表示h1-h6,上图可以看出,只到h6,而且h1下面会有一条横线,注意,#号后面有空格 第二种:      这种方式好像只能 ...

  2. leetcode-3无重复字符的最长子串

    题目原题: 给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: s = "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 ...

  3. Mybaits 的优点?

    1.基于 SQL 语句编程,相当灵活,不会对应用程序或者数据库的现有设计造成任 何影响,SQL 写在 XML 里,解除 sql 与程序代码的耦合,便于统一管理:提供 XML 标签,支持编写动态 SQL ...

  4. 转:怎样理解OOP?OOP又是什么?

    本文转载至:https://blog.csdn.net/q34323201/article/details/80198271. OOP面向对象编程.OOP思想中很重要的有五点,类,对象,还有面向对象的 ...

  5. List、Set、Map 是否继承自 Collection 接口?

    List.Set 是,Map 不是.Map 是键值对映射容器,与 List 和 Set 有明显的区别, 而 Set 存储的零散的元素且不允许有重复元素(数学中的集合也是如此),List 是线性结构的容 ...

  6. STM32试题及答案

    一.选择题 1.Cortex-M处理器采用的架构是(  D  ) (A)v4T               (B)v5TE              (C)v6                (D)v ...

  7. 比较数字范围:判断number存在(minRange ~ maxRange)范围中

    一.使用场景 当需要比较范围时 如: 这种情况,如果要写三个表达式会很长,这时候就可以用这个工具类进行比较 number:用户输入(长,宽,高) minRange: 0.0 maxRange:33 二 ...

  8. (stm32f103学习总结)—USART串口通信

    一. USART简介 USART即通用同步异步收发器,它能够灵活地与外部设备进行全双工 数据交换,满足外部设备对工业标准 NRZ 异步串行数据格式的要求. UART即通用异步收发器,它是在USART基 ...

  9. 如何正确的阅读Datasheet?

    不仅仅是芯片,包括工具.设备几乎任何电子产品,都需要去阅读它的datasheet,除了包括最低.最高要求,特点,建议和用途及其兼容的设备等等,更重要的是原厂商以一个成功者的身份去告诉你一些注意事项. ...

  10. 小程序图片轮播特效swiper(纯手打)

    前言 一个月前还是用vue做微信H5,后面公司业务发展,入坑小程序,做了几款小程,跑了不少坑, 也会陆续在后面几节跟大家分享. 在这节给大家分享这个 小程序图片轮播实现方案 初步的实现思路 我要实现的 ...