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

Prometheus使用Recoding Rules优化性能

通过PromQL可以实时对Prometheus中采集到的样本数据进行查询,聚合以及其它各种运算操作。而在某些PromQL较为复杂且计算量较大时,直接使用PromQL可能会导致Prometheus响应超时的情况。这时需要一种能够类似于后台批处理的机制能够在后台完成这些复杂运算的计算,对于使用者而言只需要查询这些运算结果即可。Prometheus通过Recoding Rule规则支持这种后台计算的方式,可以实现对复杂查询的性能优化,提高查询效率。

定义Recoding rules

在Prometheus配置文件中,通过rule_files定义recoding rule规则文件的访问路径。

rule_files:
[ - <filepath_glob> ... ]

每一个规则文件通过以下格式进行定义:

groups:
[ - <rule_group> ]

一个简单的规则文件:

groups:
- name: example
rules:
- record: job:http_inprogress_requests:sum
expr: sum(http_inprogress_requests) by (job)

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 ]
rules:
[ - <rule> ... ]

与告警规则一致,一个group下可以包含多条规则rule

# 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> ]

根据规则中的定义,Prometheus会在后台完成expr中定义的PromQL表达式计算,并且将计算结果保存到新的时间序列record中。同时还可以通过labels为这些样本添加额外的标签。

这些规则文件的计算频率与告警规则计算频率一致,

都通过global.evaluation_interval定义:

global:
[ evaluation_interval: <duration> | default = 1m ]

在这里插入图片描述

http://www.dtcms.com/a/164014.html

相关文章:

  • 20250429-李彦宏口中的MCP:AI时代的“万能接口“
  • 微服务学习笔记
  • AWS MSK 集群升级前配置检查:保障升级平稳进行的关键步骤
  • 基于PyTorch的图像分类特征提取与模型训练文档
  • MapReduce的shuffle过程详解
  • 【C++初阶】--- 模板进阶
  • 将infinigen功能集成到UE5--在ue里面写插件(python和c++)
  • 在Mybatis中写sql的常量应用
  • Redis Sentinel 和 Redis Cluster 各自的原理、优缺点及适用场景是什么?
  • 同一个路由器接口eth0和ppp0什么不同?
  • springboot中有关数据库信息转换的处理
  • Opencv中图像深度(Depth)和通道数(Channels)区别
  • MySQL事务隔离级别的实现原理MVCC
  • 51c自动驾驶~合集37
  • 「国产嵌入式仿真平台:高精度虚实融合如何终结Proteus时代?」——从教学实验到低空经济,揭秘新一代AI赋能的产业级教学工具
  • 夜族觉醒 服务搭建 异地联机 保姆教程 流畅不卡顿
  • 【linux网络】网络基础概念
  • 流量守门员:接口限流艺术
  • 软件设计师-软考知识复习(2)
  • vue3+flex动态的绘制蛇形时间轴
  • Python小程序:上班该做点摸鱼的事情
  • vue3+Nest.js项目 部署阿里云
  • 字节跳动社招面经 —— BSP驱动工程师(4)
  • vue.js中的一些事件修饰符【前端】
  • uni-app 中封装全局音频播放器
  • 深入蜂窝物联网 第四章 Cat-1 与 5G RedCap:带宽、低时延与未来趋势
  • 五、UI自动化测试05--PyTest框架
  • 【SpringBoot】基于MybatisPlus的博客管理系统(1)
  • 【Unity】使用Socket建立客户端和服务端并进行通信的例子
  • 东土科技NewPre系列智能控制器的创新之旅