PromQL:rate() 函数是什么意思?

如何解决PromQL:rate() 函数是什么意思?

我有一个关于 PromQL 及其查询函数 rate() 以及如何正确使用它的问题。在我的应用程序中,我有一个线程正在运行,我使用 Micrometer 的计时器来监视线程的运行时间。使用 Timer 会为您提供一个后缀为 _count 的计数器和另一个后缀为 _sum 所花费的秒数总和的计数器。例如。 my_metric_sum 和 my_metric_count。

我的原始数据如下所示(抓取间隔 30 秒,距离向量 5m):

enter image description here

现在根据文档,https://prometheus.io/docs/prometheus/latest/querying/functions/#rate 计算范围向量中时间序列的每秒平均增长率(此处为 5m)。

现在我的问题是:我为什么要那样?我的执行运行时的相对变化对我来说似乎毫无用处。事实上,仅使用 sum/count 看起来更有用,因为它为我提供了每个时刻的平均绝对持续时间。同时,这让我感到困惑,在我找到的文档中

要从名为 http_request_duration_seconds 的直方图或摘要计算过去 5 分钟内的平均请求持续时间,请使用以下表达式:

率(http_request_duration_seconds_sum[5m])/率(http_request_duration_seconds_count[5m])

来源:https://prometheus.io/docs/practices/histograms/

但据我了解文档,这个表达式似乎会计算请求持续时间的每秒平均增加率,即不是请求平均需要多长时间,而是请求持续时间改变了多少过去 5 分钟的平均值。

解决方法

虽然我不熟悉 Micrometer Timer,但您描述的指标属于摘要类型。它计算 _count 中的“事件”,并对 _sum 中的事件大小求和,例如持续时间、经过时间等。 如果您现在执行 rate(metric_count[5m]),您将获得每秒 500 万次事件的平均速率。如果你想知道 5m 窗口内这些事件的平均持续时间,你可以 rate(metric_sum[5m]) / rate(metric_count[5m])。如果您尝试除以 metric_sum/metric_count,您将获得所有时间(自计数器重置以来)的平均值,而不是某个时间点的 5m 平均值。 在某种程度上,为此使用 rate() 看起来有点有趣。使用 increase() 对我来说似乎更直观,但在数学上它与 rate() 完全相同,只是一个 increase()/range,因此这些范围在 rate(metric_sum[5m]) / rate(metric_count[5m]) 中相互抵消。

,

首先 - 使用与您的用例匹配的工具。

第二 - 无论您选择什么,验证数据。与其在停电期间或与愤怒的客户/用户发生冲突时,不如现在就做。

第三 - <head> <link rel="stylesheet" href="styles.css"> <title>Document</title> </head> <style> body { background-color: grey; } .main { height: 50%; width: 70%; margin: 10% 15%; background-color: white; display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr; } .box { height: 100%; width: 100%; border: 1px solid black; } .box:nth-child(even) { background: burlywood; } /* #pawn { background: url(https://svgsilh.com/svg/3413417.svg) center; background-size: cover; }*/ </style> <body> <div class="main"> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box" id="pawn"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="100%" height="100%" viewBox="0 0 1280.000000 1280.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none"> <path d="M6240 9660 c-210 -37 -369 -113 -507 -244 -142 -134 -246 -294 -278 -427 -19 -83 -19 -215 1 -319 42 -221 151 -394 326 -517 84 -59 128 -104 128 -132 0 -27 -37 -69 -78 -90 -21 -10 -93 -37 -162 -61 -141 -48 -277 -111 -315 -146 -19 -17 -25 -33 -25 -63 0 -66 17 -88 124 -159 273 -179 387 -297 461 -481 60 -148 91 -444 75 -725 -15 -251 -48 -401 -126 -561 -76 -159 -177 -271 -394 -438 -98 -75 -103 -83 -125 -182 -10 -47 -72 -98 -146 -120 -199 -58 -350 -173 -472 -358 -65 -97 -100 -178 -127 -290 -37 -154 -25 -237 46 -316 26 -29 44 -58 42 -68 -2 -10 -37 -36 -78 -58 -95 -53 -129 -95 -136 -166 -14 -146 92 -208 445 -259 805 -116 2540 -100 3129 29 214 47 282 98 282 211 0 83 -41 135 -150 190 -49 25 -70 45 -70 66 0 2 18 24 40 48 53 58 70 102 70 183 0 321 -278 690 -586 778 -128 37 -166 72 -185 167 -13 66 -7 59 -208 219 -181 144 -292 299 -360 504 -47 144 -62 256 -68 503 -10 422 37 637 182 830 63 84 138 148 313 267 131 89 148 104 161 141 13 37 12 44 -5 80 -16 33 -32 46 -113 85 -51 26 -150 66 -220 89 -194 66 -234 92 -234 150 0 38 26 66 124 135 218 153 340 398 340 680 0 161 -45 287 -152 428 -181 239 -398 365 -702 406 -103 14 -142 13 -267 -9z"/> </g> </svg></div> <div class="box" id="pawn"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="100%" height="100%" viewBox="0 0 1280.000000 1280.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,-0.100000)" fill="#000000" stroke="none"> <path d="M6240 9660 c-210 -37 -369 -113 -507 -244 -142 -134 -246 -294 -278 -427 -19 -83 -19 -215 1 -319 42 -221 151 -394 326 -517 84 -59 128 -104 128 -132 0 -27 -37 -69 -78 -90 -21 -10 -93 -37 -162 -61 -141 -48 -277 -111 -315 -146 -19 -17 -25 -33 -25 -63 0 -66 17 -88 124 -159 273 -179 387 -297 461 -481 60 -148 91 -444 75 -725 -15 -251 -48 -401 -126 -561 -76 -159 -177 -271 -394 -438 -98 -75 -103 -83 -125 -182 -10 -47 -72 -98 -146 -120 -199 -58 -350 -173 -472 -358 -65 -97 -100 -178 -127 -290 -37 -154 -25 -237 46 -316 26 -29 44 -58 42 -68 -2 -10 -37 -36 -78 -58 -95 -53 -129 -95 -136 -166 -14 -146 92 -208 445 -259 805 -116 2540 -100 3129 29 214 47 282 98 282 211 0 83 -41 135 -150 190 -49 25 -70 45 -70 66 0 2 18 24 40 48 53 58 70 102 70 183 0 321 -278 690 -586 778 -128 37 -166 72 -185 167 -13 66 -7 59 -208 219 -181 144 -292 299 -360 504 -47 144 -62 256 -68 503 -10 422 37 637 182 830 63 84 138 148 313 267 131 89 148 104 161 141 13 37 12 44 -5 80 -16 33 -32 46 -113 85 -51 26 -150 66 -220 89 -194 66 -234 92 -234 150 0 38 26 66 124 135 218 153 340 398 340 680 0 161 -45 287 -152 428 -181 239 -398 365 -702 406 -103 14 -142 13 -267 -9z"/> </g> </svg></div> <div class="box" id="pawn"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="100%" height="100%" viewBox="0 0 1280.000000 1280.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,-0.100000)" fill="#000000" stroke="none"> <path d="M6240 9660 c-210 -37 -369 -113 -507 -244 -142 -134 -246 -294 -278 -427 -19 -83 -19 -215 1 -319 42 -221 151 -394 326 -517 84 -59 128 -104 128 -132 0 -27 -37 -69 -78 -90 -21 -10 -93 -37 -162 -61 -141 -48 -277 -111 -315 -146 -19 -17 -25 -33 -25 -63 0 -66 17 -88 124 -159 273 -179 387 -297 461 -481 60 -148 91 -444 75 -725 -15 -251 -48 -401 -126 -561 -76 -159 -177 -271 -394 -438 -98 -75 -103 -83 -125 -182 -10 -47 -72 -98 -146 -120 -199 -58 -350 -173 -472 -358 -65 -97 -100 -178 -127 -290 -37 -154 -25 -237 46 -316 26 -29 44 -58 42 -68 -2 -10 -37 -36 -78 -58 -95 -53 -129 -95 -136 -166 -14 -146 92 -208 445 -259 805 -116 2540 -100 3129 29 214 47 282 98 282 211 0 83 -41 135 -150 190 -49 25 -70 45 -70 66 0 2 18 24 40 48 53 58 70 102 70 183 0 321 -278 690 -586 778 -128 37 -166 72 -185 167 -13 66 -7 59 -208 219 -181 144 -292 299 -360 504 -47 144 -62 256 -68 503 -10 422 37 637 182 830 63 84 138 148 313 267 131 89 148 104 161 141 13 37 12 44 -5 80 -16 33 -32 46 -113 85 -51 26 -150 66 -220 89 -194 66 -234 92 -234 150 0 38 26 66 124 135 218 153 340 398 340 680 0 161 -45 287 -152 428 -181 239 -398 365 -702 406 -103 14 -142 13 -267 -9z"/> </g> </svg></div> <div class="box" id="pawn"><svg xmlns="http://www.w3.org/2000/svg" version="1.0"width="100%" height="100%" viewBox="0 0 1280.000000 1280.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,-0.100000)" fill="#000000" stroke="none"> <path d="M6240 9660 c-210 -37 -369 -113 -507 -244 -142 -134 -246 -294 -278 -427 -19 -83 -19 -215 1 -319 42 -221 151 -394 326 -517 84 -59 128 -104 128 -132 0 -27 -37 -69 -78 -90 -21 -10 -93 -37 -162 -61 -141 -48 -277 -111 -315 -146 -19 -17 -25 -33 -25 -63 0 -66 17 -88 124 -159 273 -179 387 -297 461 -481 60 -148 91 -444 75 -725 -15 -251 -48 -401 -126 -561 -76 -159 -177 -271 -394 -438 -98 -75 -103 -83 -125 -182 -10 -47 -72 -98 -146 -120 -199 -58 -350 -173 -472 -358 -65 -97 -100 -178 -127 -290 -37 -154 -25 -237 46 -316 26 -29 44 -58 42 -68 -2 -10 -37 -36 -78 -58 -95 -53 -129 -95 -136 -166 -14 -146 92 -208 445 -259 805 -116 2540 -100 3129 29 214 47 282 98 282 211 0 83 -41 135 -150 190 -49 25 -70 45 -70 66 0 2 18 24 40 48 53 58 70 102 70 183 0 321 -278 690 -586 778 -128 37 -166 72 -185 167 -13 66 -7 59 -208 219 -181 144 -292 299 -360 504 -47 144 -62 256 -68 503 -10 422 37 637 182 830 63 84 138 148 313 267 131 89 148 104 161 141 13 37 12 44 -5 80 -16 33 -32 46 -113 85 -51 26 -150 66 -220 89 -194 66 -234 92 -234 150 0 38 26 66 124 135 218 153 340 398 340 680 0 161 -45 287 -152 428 -181 239 -398 365 -702 406 -103 14 -142 13 -267 -9z"/> </g> </svg></div> <div class="box" id="pawn"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="100%" height="100%" viewBox="0 0 1280.000000 1280.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,-0.100000)" fill="#000000" stroke="none"> <path d="M6240 9660 c-210 -37 -369 -113 -507 -244 -142 -134 -246 -294 -278 -427 -19 -83 -19 -215 1 -319 42 -221 151 -394 326 -517 84 -59 128 -104 128 -132 0 -27 -37 -69 -78 -90 -21 -10 -93 -37 -162 -61 -141 -48 -277 -111 -315 -146 -19 -17 -25 -33 -25 -63 0 -66 17 -88 124 -159 273 -179 387 -297 461 -481 60 -148 91 -444 75 -725 -15 -251 -48 -401 -126 -561 -76 -159 -177 -271 -394 -438 -98 -75 -103 -83 -125 -182 -10 -47 -72 -98 -146 -120 -199 -58 -350 -173 -472 -358 -65 -97 -100 -178 -127 -290 -37 -154 -25 -237 46 -316 26 -29 44 -58 42 -68 -2 -10 -37 -36 -78 -58 -95 -53 -129 -95 -136 -166 -14 -146 92 -208 445 -259 805 -116 2540 -100 3129 29 214 47 282 98 282 211 0 83 -41 135 -150 190 -49 25 -70 45 -70 66 0 2 18 24 40 48 53 58 70 102 70 183 0 321 -278 690 -586 778 -128 37 -166 72 -185 167 -13 66 -7 59 -208 219 -181 144 -292 299 -360 504 -47 144 -62 256 -68 503 -10 422 37 637 182 830 63 84 138 148 313 267 131 89 148 104 161 141 13 37 12 44 -5 80 -16 33 -32 46 -113 85 -51 26 -150 66 -220 89 -194 66 -234 92 -234 150 0 38 26 66 124 135 218 153 340 398 340 680 0 161 -45 287 -152 428 -181 239 -398 365 -702 406 -103 14 -142 13 -267 -9z"/> </g> </svg></div> </div> </body> </html> _count直方图摘要的特征。采样频率在这里并不重要,只要它小于 _bucket 函数的 [5m] 分组即可。

该比率只是为您提供“在这五分钟 (rate()) 内发生了多少次事件”的数据点。

一般说明 - Prometheus 中的 [5m] 概念引起了很多混淆。它在太多人之间争论不休。他们可能应该叫它别的东西。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-