当前位置: 首页 > 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 ]

在这里插入图片描述

相关文章:

  • 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动态的绘制蛇形时间轴
  • 民生银行一季度净利127.42亿降逾5%,营收增7.41%
  • 贵州茅台一季度净利268亿元增长11.56%,系列酒营收增近两成
  • 辽宁省全力开展辽阳一饭店火灾事故救援处置工作
  • 解放日报头版聚焦“人民城市”:共建共享展新卷
  • 对话|贝聿铭设计的不只是建筑,更是生活空间
  • 上海乐高乐园建设进入最后冲刺,开园限量纪念年卡将于5月开售