当前位置: 首页 > news >正文

Prometheus 记录规则和警报规则

前提环境:

  • Docker环境

涉及参考文档:

  • Prometheus 录制规则
  • Prometheus 警报规则

语法检查规则

promtool check rules /path/to/example.rules.yml

一:录制规则语法

groups 语法:

groups:[ - <rule_group> ]

rule_group 语法

# The name of the group. Must be unique within a file.
name: <string># How often rules in the group are evaluated.
[ interval: <duration> | default = global.evaluation_interval ]# Limit the number of alerts an alerting rule and series a recording
# rule can produce. 0 is no limit.
[ limit: <int> | default = 0 ]rules:[ - <rule> ... ]

rules 语法

# The name of the time series to output to. Must be a valid metric name.
record: <string># The PromQL expression to evaluate. Every evaluation cycle this is
# evaluated at the current time, and the result recorded as a new set of
# time series with the metric name as given by 'record'.
expr: <string># Labels to add or overwrite before storing the result.
labels:[ <labelname>: <labelvalue> ]

示例规则文件:

groups:
- name: cpu-noderules:- record: job_instance_mode:node_cpu_seconds:avg_rate5mexpr: avg by (job, instance, mode) (rate(node_cpu_seconds_total{instance="10.1.32.231"}[5m]))labels:job_instance_mode: node_cpu_seconds

在这里插入图片描述

二:警报规则语法

警报规则允许您根据 Prometheus 自定义警报条件 表达式语言表达式和发送有关触发警报的通知 到外部服务。

语法格式:

# The name of the alert. Must be a valid label value.
alert: <string>   # 告警名称# The PromQL expression to evaluate. Every evaluation cycle this is
# evaluated at the current time, and all resultant time series become
# pending/firing alerts.
expr: <string>    # 自定义语法# Alerts are considered firing once they have been returned for this long.
# Alerts which have not yet fired for long enough are considered pending.
[ for: <duration> | default = 0s ]    # 持续设定时间才触发,在此之间一直处于等待告警状态(pending)# Labels to add or overwrite for each alert.
labels:[ <labelname>: <tmpl_string> ]	  # 告警名称标签# Annotations to add to each alert.
annotations:						  # [ <labelname>: <tmpl_string> ]

定义警报规则:

标签和注释值可以使用控制台进行模板化模板。该变量保存警报实例的标签键/值对。已配置的 可以通过变量访问外部标签。该变量保存警报实例的评估值

groups:
- name: Dos端口探针rules:- alert: Dos端口探针		#告警名称expr: probe_success{job="Dos-Port-Status"}==0   #匹配规则for: 1m					# 一直持续时间,才触发告警规则labels:					# 标签部分severity: criticalteam: "{{ $labels.job }}" 	# $labels.job ——> Prometheus 主配置文件定义的Job名称annotations:			# 注解部分summary: '{{$labels.env}} TCP探测失败' # 采集主机的标签名称description: '{{ $labels.env}}{{ $labels.name}}】TCP探测端口失败,当前状态码:{{$value}}' # 采集主机的标签名称

在这里插入图片描述

触发效果
在这里插入图片描述

http://www.lryc.cn/news/11823.html

相关文章:

  • (API)接口测试的关键技术
  • 快速排序算法原理 Quicksort —— 图解(精讲) JAVA
  • linux环境搭建私有gitlab仓库
  • SpringSecurity授权
  • 学习 Python 之 Pygame 开发坦克大战(一)
  • 2.5|iot冯|方元-嵌入式linux系统开发入门|2.13+2.18
  • 一起Talk Android吧(第四百九十六回:自定义View实例二:环形进度条)
  • 上传图片尺寸校验
  • 【Python】缺失值处理和拉格朗日插值法(含源代码实现)
  • SpringCloudAlibaba-Sentinel
  • 【程序化天空盒】过程记录02:云扰动 边缘光 消散效果
  • 链表OJ(三) 反转链表合集
  • SQLSERVER2019安装步骤过程
  • Java模块化概述
  • Connext DDSPersistence Service持久性服务(2)
  • MongoDB
  • python 迭代器生成器
  • Iceberg基于Spark MergeInto语法实现数据的增量写入
  • JavaScript Array(数组) 对象
  • Debian如何更换apt源
  • Connext DDSPersistence Service持久性服务
  • 自抗扰控制ADRC之微分器TD
  • 链表学习之复制含随机指针的链表
  • 【人脸检测】Yolov5Face:优秀的one-stage人脸检测算法
  • 【Unity3d】Unity与Android之间通信
  • Allegro如何更改DRC尺寸大小操作指导
  • Mongodb WT_PANIC: WiredTiger library panic
  • 【HTML】HTML 表格总结 ★★★ ( 表格标签 | 行标签 | 单元格标签 | 表格标签属性 | 表头单元格标签 | 表格标题标签 | 合并单元格 )
  • linux013之文件和目录的权限管理
  • 设计模式之状态模式