04-prometheus

一、Prometheus简介

1、介绍

Prometheus(普罗米修斯)基于Go语言开发,是一套开源且免费的监控系统。

Prometheus于2016年加入CNCF(云原生基金会)成为继Kubernetes之后的第二个托管项目,目前主要应用在云原生容器领域的监控解决方案。

Prometheus使用时序数据库TSDB(Time Series Database)存储指标数据,既指标信息与记录的时间戳一起存储的特点。

  • 官网地址:https://Prometheus.io
  • 项目托管:https://github.com/prometheus

Prometheus特点:

  • 基于HTTP的 pull(拉取)方式采集指标数据,利用TSDB(时序数据库)存储指标数据
  • PromQL 作为TSDB数据库的灵活查询语言,可完成复杂的查询操作
  • PushGateway作为Prometheus的代理节点,可用于分布式监控
  • 可通过配置文件与动态发现规则发现监控目标
  • 提供web界面图形化数据展示,支持第三方数据展示(如:Grafana)

二、软件包下载及安装

Prometheus相关的软件包是编译后的二进制包,也不依赖于任何的第三方软件,只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus

对于非Docker用户,可以从https://prometheus.io/download/找到最新版本的Prometheus Sevrer软件包

需要下载的软件包:

prometheus #服务端程序,提供监控服务

node_exporter #Linux主机被控端程序,用于采集节点监控指标数据

alertmanager #报警程序

下载方式

wget https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz

1、安装node_exporter

提示:在prom主机操作

#解压软件包
tar -xf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local/
#进入解压路径并修改目录名字
cd /usr/local/
mv node_exporter-1.2.2.linux-amd64/ node_exporter

#添加系统启动服务(可通过systemctl命令管理服务,否则服务以前台形式运行,占用前台终端)
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Restart=on-failure
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target

#启动服务&&设置服务随机自启&&查看服务状态
systemctl start node_exporter.service
systemctl status node_exporter.service
systemctl enable node_exporter.service

#查看服务端口信息
ss -ntlpl | grep node_exporter
tcp     LISTEN     0     128     :::9100    :::*    users:(("node_exporter",pid=56984,fd=3))

2、安装prometheus

提示:在prom主机操作

#解压软件包
tar -xf prometheus-2.29.2.linux-amd64.tar.gz -C /usr/local
#进入解压路径
cd /usr/local/
mv prometheus-2.29.2.linux-amd64/ prometheus

#添加系统启动服务,指定了配置文件、数据库文件地址,指定了prometheus的端口
vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.external-url=http://0.0.0.0:9090
[Install]
WantedBy=multi-user.target

#启动服务&&设置服务随机自启&&查看服务运行状态
systemctl start prometheus
systemctl status prometheus
systemctl enable prometheus

#查看服务端口信息
ss -ntlp | grep prometheus

3、添加被控主机

#解压软件包
tar -xf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local/
#进入解压路径
cd /usr/local/
mv node_exporter-1.2.2.linux-amd64/ node_exporter

#添加系统启动服务(可通过systemctl命令管理服务,否则服务以前台形式运行,占用前台终端)
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Restart=on-failure
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target

#启动服务&&设置服务随机自启&&查看服务状态
systemctl start node_exporter.service
systemctl status node_exporter.service
systemctl enable node_exporter.service

#查看服务端口信息
ss -ntlpl | grep node_exporter

4、部署Cadvisor

Cadvisor是由Google(谷歌)公司开发的一款开源的容器度量指标数据采集可视化系统,专门用于获取容器内的指标数据,它被内嵌到k8s中作为k8s的监控组件

docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8888:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor

Cadvisor为prometheus提供了时序数据格式,该格式为prometheus识别的格式。

  • 访问cadvisor:http://server_ip:8888

5、添加监控对象

提示:prometheus主机添加监控对象

主配置文件为prometheus.yml,配置文件遵循的是YAML语法格式,整体分为三个模块global rule_files ,和scrape_configs

#备份配置文件
cd /usr/local/prometheus
cp prometheus.yml prometheus.yml.bak
vim prometheus.yml
#global模块为Prometheus 服务器的全局配置
global:
	scrape_interval: 15s # 抓取指标数据时间间隔,默认为1分钟
	evaluation_interval: 15s # 规则发现时间间隔,默认为1分钟
# scrape_timeout is set to the global default (10s). #收集数据超时时间,默认10秒
# alerting模块用于关联prometheus报警配置,需指定alertmanager组件的ip和端口
alerting:
	alertmanagers:
		- static_configs:
		- targets:
# - alertmanager:9093
# rule_files模块指定Prometheus服务器加载的任何规则的位置(例如:告警规则)
rule_files:
	# - "first_rules.yml"
	# - "second_rules.yml"

# scrape_configs模块控制Prometheus监控的资源,Prometeheus也将自身作为被监控的对象,用于监控自身健康状态
scrape_configs:
	- job_name: "prometheus"
static_configs:
	- targets: ["localhost:9090","192.168.0.10:9100"]
	- job_name: "container"
static_configs:
	- targets: ["192.168.0.10:8888"] # 添加cadvisor为监控对象

重启服务prometheus

systemctl restart prometheus
  • 浏览器:http://192.168.0.30:9090/

三、Grafana数据展示

Grafana是一款用Go语言开发的开源数据可视化平台,可以做数据监控和数据统计 ,并带有报警功能。

  • 官网: https://grafana.com

特点:

  • **可视化:**快速和灵活的客户端图形具有多种选项。面板插件为许多不同的方式可视化指标和日志。
  • **报警:**可视化地为最重要的指标定义警报规则。Grafana将持续评估它们,并发送通知。
  • **通知:**警报更改状态时,它会发出通知。接收电子邮
  • **动态仪表盘:**使用模板变量创建动态和可重用的仪表板,这些模板变量作为下拉菜单出现在仪表板顶部。
  • **混合数据源:**在同一个图中混合不同的数据源!可以根据每个查询指定数据源。这甚至适用于自定义数据源。
  • **注释:**注释来自不同数据源图表。将鼠标悬停在事件上可以显示完整的事件元数据和标记。
  • **过滤器:**过滤器允许您动态创建新的键/值过滤器,这些过滤器将自动应用于使用该数据源的所有查询。

Grafana安装

提示:在prometheus主机安装

  • 软件包可从清华大学源下载:https://mirrors.tuna.tsinghua.edu.cn/
#下载软件包(这个版本有问题)
#wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/grafana-7.2.1-
#1.x86_64.rpm
#下载新版本
wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/grafana-8.4.0-1.x86_64.rpm
#安装grafana
yum -y install grafana-8.4.0-1.x86_64.rpm

#启动服务&&设置服务随机自启&&查看服务运行状态
systemctl start grafana-server
systemctl status grafana-server
systemctl enable grafana-server

#查看服务端口信息
ss -ntlp | grep grafana 
LISTEN 0 128 :::3000 :::* users:(("grafanaserver",pid=7907,fd=6))
  • 访问:浏览器访问:http://server_ip:3000

四、故障报警

Prometheus支持故障触发告警功能,但是告警功能由Alertmanager组件实现,Alertmanager支持多种告警媒介类型,如:邮件、短信、微信、钉钉等告警功能,不同的报警媒介,告警的配置方式也有所不同

在Prometheus上定义告警规则生成告警通知,Alertmanager接收到Prometheus告警通知后,按需分别进行处理,将告警信息发送给接收人。

1、安装Alertmanager

#解压软件包&&进入解压路径
tar -xf alertmanager-0.23.0.linux-amd64.tar.gz -C /usr/local
cd /usr/local
#修改名称
mv alertmanager-0.23.0.linux-amd64/ alertmanager

#添加系统启动服务
vim /etc/systemd/system/alertmanager.service
[Unit]
Description=Alertmanager
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alertmanager.yml
[Install]
WantedBy=multi-user.target

#启动服务&&设置服务随机自启
systemctl start alertmanager
#查看服务端口
netstat -ntlp | grep alertmanager
:::9093 :::* #alertmanager监听端口
:::9094 :::* #集群内部通讯端口
  • 访问测试:http://server_ip:9093

2、配置文件介绍

vim alertmanager.yml
route: #根路由,所有告警信息进入根路由后,由根路由设置报警的分发策略
	group_by: ['alertname'] #定义分组规则,group_by中定义标签名称
	group_wait: 30s #当收到告警的时候,等待30秒看是否还有相同告警,如果有就一起发出去
	group_interval: 10s #发送告警时间间隔
	repeat_interval: 30m #同一个报警重复发送的间隔时间
	receiver: 'web.hook' #报警接收器,可选择多种接收方式(如邮件、微信等)以下内容省略...

接收器详细参数配置文档:

email: https://prometheus.io/docs/alerting/latest/confifiguration/#email_confifig

webhook: https://prometheus.io/docs/alerting/latest/confifiguration/#webhook_confifig

wechat: https://prometheus.io/docs/alerting/latest/confifiguration/#wechat_confifig

pagerduty:https://prometheus.io/docs/alerting/latest/confifiguration/#pagerduty_confifig

3、邮件报警

可以通过idea工具编写yaml文件

cat alertmanager.yml
global:
  resolve_timeout: 1h #定义了当Alertmanager持续多长时间未接收到告警后标记告警状态为resolved(已解决)
  smtp_smarthost: 'smtp.163.com:25' #SMTP服务器地址及端口
  smtp_from: 'robber@163.com' #发件人,填写你的163邮箱
  smtp_auth_username: 'robber@163.com' #与上面保持一致
  smtp_auth_password: 'VCTGSXMXFRPLJDWW' #邮箱的授权码
  smtp_require_tls: false #不使用加密认证

templates: #指定告警模板文件位置
  - './template/test.tmpl' #模板文件地址,默认不存在,需要手动创建

route:
  group_by: ['alertname'] # 定义分组规则,group_by中定义标签名称
  group_wait: 10s # 当收到告警的时候,等待10秒看是否还有相同告警,如果有就一起发出去
  group_interval: 10s # 发送告警时间间隔
  repeat_interval: 30m # 同一个报警重复发送的间隔时间
  receiver: 'email' # 报警接收器

receivers:
- name: 'email'
  email_configs:
  - to: 'robber2000@163.com'
    send_resolved: true # 故障恢复后发送邮件

4、创建告警模板

一般来说,在告警规则文件的annotations中使用 summary 描述告警的概要信息, description 用于描述告警的详细信息。

同时Alertmanager的UI也会根据这两个标签值,显示告警信息。为了让告警信息具有更好的可读性,Prometheus支持模板化label和annotations的中标签的值。

通过 l a b e l s . 变量可以访问当前告警实例中指定标签的值。 ‘ labels. 变量可以访问当前告警实例中指定标签的值。` labels.变量可以访问当前告警实例中指定标签的值。value则可以获取当前PromQL`表达式计算的样本值。

#创建模板文件,路径为alertmanager安装目录下
[root@prom prometheus]# cd /usr/local/alertmanager/
[root@prom alertmanager]# mkdir template && cd template/

#创建告警模板文件
[root@prom template]# cat test.tmpl
{{ define "email.default.html" }}
{{ range .Alerts }}
告警实例: {{ .Labels.instance }} <br>
告警级别: {{ .Labels.severity }} <br>
告警类型: {{ .Labels.alertname }} <br>
触发阀值:{{ .Annotations.value }} <br>
告警详情: {{ .Annotations.description }} <br>
告警时间:{{ .StartsAt.Local.Format "2006-01-02 15:04:05"}} <br>
{{ end }}{{ end }}

检测配置alertmanager.yml文件语法是否正确

[root@prom template]# cd ..
[root@prom alertmanager]# ./amtool check-config alertmanager.yml
Checking 'alertmanager.yml' SUCCESS
Found:
	- global config
	- route
	- 0 inhibit rules
	- 1 receivers
	- 1 templates
SUCCESS

#重启alertmanager服务&&查看服务状态
[root@prom alertmanager]# systemctl restart alertmanager

5、开启邮件告警功能

为了能够让Prometheus能够启用定义的告警规则,我们需要在Prometheus全局配置文件中通过rule_fifiles指定 一组告警规则文件的访问路径,Prometheus启动后会自动扫描这些路径下规则文件中定义的内容,并且根据这些规则计算是否向外部发送通知:

vim prometheus.yml
#global模块为Prometheus 服务器的全局配置
global:
	scrape_interval: 15s # 抓取指标数据时间间隔,默认为1分钟
	evaluation_interval: 15s # 规则发现时间间隔,默认为1分钟

# scrape_timeout is set to the global default (10s). #收集数据超时时间,默认10秒
# alerting模块用于关联prometheus报警配置,需指定alertmanager组件的ip和端口
alerting:
  alertmanagers:
    - static_configs:
        - targets:
            - 192.168.227.112:9093 #取消注释,指定alertmanager主机IP与端口

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "first_rules.yml"  #去注释,这个作为告警规则文件
  # - "second_rules.yml"
# scrape_configs模块控制Prometheus监控的资源,Prometeheus也将自身作为被监控的对象,用于监控自身健康状态
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.227.111:9100"]


6、配置告警规则

创建fifirst_rules.yml添加告警规则,路径为/usr/local/prometheus/一条典型的告警规则如下所示:告警大致含义为如果主机down了,就触发告警

cat first_rules.yml
groups: #告警分组
- name: 'Linux Instances' #组名
  rules:
    - alert: "主机状态告警" #告警状态
      expr: up == 0 #告警指标,UP指标的值等于0表示Down状态,1表示正常
      for: 10s #等待10秒发送告警信息
      labels: #定义一些告警的具体详细内容,指定对应的标签名称
        severity: '紧急' #告警级别
      annotations: #告警信息描述
        summary: "服务名:{{$labels.alertname}} 主机状态告警"
        #描述信息自定义
        description: "{{ $labels.alertname }} 主机以宕机10秒"
        #描述信息自定义
        value: "{{ $value }}"

在告警规则文件中,我们可以将一组相关的规则设置定义在一个group下,在每一个group中我们可以定义多个告警 规则(rule)。

一条告警规则主要由以下几部分组成:

  • alert:告警规则的名称。
  • expr:基于PromQL表达式告警触发条件,用于计算是否有时间序列满足该条件。
  • for:评估等待时间,可选参数。用于表示只有当触发条件持续一段时间后才发送告警。在等待期间新产生告警 的状态为pending。
  • labels:自定义标签,允许用户指定要附加到告警上的一组附加标签。
  • annotations:用于指定一组附加信息,比如用于描述告警详细信息的文字等,annotations的内容在告警产生时会一同作为参数发送到Alertmanager。
  • value:则可以获取当前PromQL表达式计算的样本值。

重启服务

systemctl restart prometheus

7、查看告警状态

用户可以通过Prometheus的Web界面查看这些告警规则 以及告警的触发状态。

8、触发告警

模拟被控主机宕机,关闭node_exporter服务即可

[root@docker02 ~]# systemctl stop node_exporter

8.1、配置CPU利用率告警

[root@prometheus-server prometheus]# vim first_rules.yml
groups:
- name: 'Linux Instances' #组名
	rules:
...
	- alert: "CPU利用率告警" #告警状态
	expr:
sum(avg(irate(node_cpu_seconds_total{mode!='idle'}[5m]))
without (cpu)) by (instance) > 0.60
	for: 20s #等待20秒发送告警信息
	labels: #指定告警级别
		severity: '警告' #告警级别
	annotations: #告警信息描述
		summary: "服务名:{{$labels.alertname}} CPU利用率告警"
		#描述信息自定义
		description: "{{ $labels.alertname }} CPU利用率达到60%" #描述信息自定义
		value: "{{ $value }}"
	- alert: "CPU利用率告警" #告警状态
		expr: (100 - (avg by (instance)(irate(node_cpu_seconds_total{job=~".*",mode="idle"}[5m]))* 100)) > 85
		for: 20s #等待20秒发送告警信息
		labels: #指定告警级别
			severity: '紧急' #告警级别
		annotations: #告警信息描述
			summary: "服务名:{{$labels.alertname}} CPU利用率告警"
			#描述信息自定义
			description: "{{ $labels.alertname }} CPU利用率达到85%" #描述信息自定义
			value: "{{ $value }}"

重启Prometheus服务

[root@prometheus-server prometheus]# systemctl restart promethues.service

被控主机模拟CPU利用率过高

[root@host31 nginx-1.20.1]# while :
do
echo hello word
done
#利用top观察CPU负载
[root@host31 ~]# top

8.2、配置内存利用率警告

groups:
- name: 'Linux Instances' #组名
  rules:
  - alert: '内存利用率告警'
    expr: avg by(instance) ((1 - (node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes) / node_memory_MemTotal_bytes) *100) > 70
    for: 3m
    labels:
      severity: '警告'
  annotations:
    summary: "服务名 {{ $labels.instance }} 内存利用率过高"
    description: "{{ $labels.instance }} 内存利用率达到70%"
    value: "{{ $value }}"
  - alert: '内存利用率告警'
    expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)/node_memory_MemTotal_bytes > 0.90
    for: 3m
    labels:
      severity: '严重'
    annotations:
      summary: "服务名 {{ $labels.instance }} 内存利用率过高"
      description: "{{ $labels.instance }} 内存利用率达到90%"
      value: "{{ $value }}"

8.3、配置磁盘利用率警告

groups:
- name: 'Linux Instances' #组名
  rules:
  - alert: '磁盘利用率告警'
    expr: (1 - node_filesystem_free_bytes{fstype!="rootfs",mountpoint!="",mountpoint!~"/(run|var|sys|dev).*"} / node_filesystem_size_bytes) * 100 > 80
    for: 2m
    labels:
      severity: '警告'
  annotations:
    summary: "服务名 {{ $labels.instance }} 磁盘利用率过高"
    description: "{{ $labels.instance }} 磁盘利用率达到80%"
    value: "{{ $value }}"
  - alert: '磁盘利用率告警'
    expr: (1 - node_filesystem_free_bytes{fstype!="rootfs",mountpoint!="",mountpoint!~"/(run|var|sys|dev).*"} /node_filesystem_size_bytes) * 100 > 90
    for: 2m
    labels:
      severity: '严重'
    annotations:
      summary: "服务名 {{ $labels.instance }} 磁盘利用率过高"
      description: "{{ $labels.instance }} 磁盘利用率达到90%"
      value: "{{ $value }}"

五、企业微信警告

  • 登录企业微信:https://work.weixin.qq.com/

创建Prometheus企业应用:【应用管理】–【创建应用】

AgentId 企业应用ID:1000028

Secret 应用密码:fBFXsKVEWvO2RwkaIpNM1cSrljIKnRrZUQYJBilCy90

企业ID:【我的企业】 wwa78d6212da74fd51

企业微信账号: Yesir

修改alertmanager.yml文件,配置微信报警媒介

cat alertmanager.yml

global: #全局配置
  resolve_timeout: 1h #定义了当Alertmanager持续多长时间未接收到告警后标记告警状态为resolved(已解决)。

templates: #指定告警模板文件位置
  - './template/test.tmpl' #模板文件地址,默认不存在,需要手动创建

route:
  group_by: ['alertname'] # 定义分组规则,group_by中定义标签名称
  group_wait: 10s # 当收到告警的时候,等待10秒看是否还有相同告警,如果有就一起发出去
  group_interval: 10s # 发送告警时间间隔
  repeat_interval: 1h # 同一个报警重复发送的间隔时间
  receiver: 'wechat' # 默认接收者

receivers: #告警接收器
  - name: 'wechat' #接收器名称
    wechat_configs: #企业微信报警配置
    - send_resolved: true #定义接收人账号信息
      agent_id: '1000026' # 自建应用的agentId
      to_user: 'Yesir' # 接收告警消息的人员Id
      api_secret: 'QS1_LMnEOFRkDreSxDcDpswZkNNfiJRtOcaWXOCfmls' # 自建应用的secret
      corp_id: 'wwa78d6212da74fd51' # 企业ID

常用告警规则配置

  - alert: CpuUsageAlert_waring
    expr: sum(avg(irate(node_cpu_seconds_total{mode!='idle'}[5m])) without (cpu)) by (instance) > 0.60
    for: 2m
    labels:
      level: warning
    annotations:
      summary: "Instance {{ $labels.instance }} CPU usagehigh"
      description: "{{ $labels.instance }} CPU usage above60% (current value: {{ $value }})"

  - alert: CpuUsageAlert_serious
    expr: (100 - (avg by (instance)(irate(node_cpu_seconds_total{job=~".*",mode="idle"}[5m]))* 100)) > 85
    for: 3m
    labels:
      level: serious
    annotations:
      summary: "Instance {{ $labels.instance }} CPU usagehigh"
      description: "{{ $labels.instance }} CPU usage above85% (current value: {{ $value }})"

  - alert: MemUsageAlert_waring
    expr: avg by(instance) ((1 -(node_memory_MemFree_bytes + node_memory_Buffers_bytes +node_memory_Cached_bytes) / node_memory_MemTotal_bytes) *100) > 70
    for: 2m
    labels:
      level: warning
    annotations:
      summary: "Instance {{ $labels.instance }} MEM usagehigh"
      description: "{{$labels.instance}}: MEM usage is above 70% (current value is: {{ $value }})"

  - alert: MemUsageAlert_serious
    expr: (node_memory_MemTotal_bytes -node_memory_MemAvailable_bytes)/node_memory_MemTotal_bytes> 0.90
    for: 3m
    labels:
      level: serious
    annotations:
      summary: "Instance {{ $labels.instance }} MEM usage high"
      description: "{{ $labels.instance }} MEM usage above 90% (current value: {{ $value }})"


_bytes + node_memory_Buffers_bytes +node_memory_Cached_bytes) / node_memory_MemTotal_bytes) *100) > 70
for: 2m
labels:
level: warning
annotations:
summary: “Instance {{ KaTeX parse error: Expected 'EOF', got '}' at position 17: …abels.instance }̲} MEM usagehigh…labels.instance}}: MEM usage is above 70% (current value is: {{ $value }})”

  • alert: MemUsageAlert_serious
    expr: (node_memory_MemTotal_bytes -node_memory_MemAvailable_bytes)/node_memory_MemTotal_bytes> 0.90
    for: 3m
    labels:
    level: serious
    annotations:
    summary: “Instance {{ $labels.instance }} MEM usage high”
    description: “{{ $labels.instance }} MEM usage above 90% (current value: {{ $value }})”

``

六、飞书告警

添加飞书群聊机器人

【。。。】->【设置】-> 【群机器人】-> 【添加机器人】-> 【自定义机器人】-> 【保存】-> 【添加关键字】

  • 分别是预警、报警、告警
  • 保存webhook链接地址https://open.feishu.cn/open-apis/bot/v2/hook/***************************

搭建prometheus-alert

prometheus-alert:适用于帮助alertmanager转发告警信息用的,如飞书告警、企业微信、邮件、腾讯短信等。

docker run -d --name prometheus-alert   -p 9099:8080   -v /root/prometheus/prometheus-alert/db:/app/db   -e PA_LOGIN_USER=alertuser   -e PA_LOGIN_PASSWORD=123456   -e PA_TITLE=prometheusAlert   -e PA_OPEN_FEISHU=1   -e PA_OPEN_DINGDING=0   -e PA_OPEN_WEIXIN=1   feiyu563/prometheus-alert:latest
  • 测试:localhost:9099
    在这里插入图片描述* 飞书告警固定格式:http://localhost:9099/prometheusalert?type=fs&tpl=prometheus-fs&fsurl=https://*************=zhangsan@xxx.com
vim alertmanager.yml

global:
  resolve_timeout: 5m
route:
  group_by: ['instance']
  group_wait: 10m
  group_interval: 10s
  repeat_interval: 10m
  receiver: 'web.hook.prometheusalert'
receivers:
- name: 'web.hook.prometheusalert'
  webhook_configs:
  - url: 'http://localhost:9099/prometheusalert?type=fs&tpl=prometheus-fs&fsurl=https://*************=zhangsan@xxx.com'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值