惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
T
Threatpost
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
S
Securelist
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
S
Secure Thoughts
MyScale Blog
MyScale Blog
O
OpenAI News
P
Palo Alto Networks Blog
美团技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
TaoSecurity Blog
TaoSecurity Blog
量子位
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
Know Your Adversary
Know Your Adversary
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
宝玉的分享
宝玉的分享
PCI Perspectives
PCI Perspectives
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
I
InfoQ
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
S
Security @ Cisco Blogs
S
Schneier on Security
B
Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Cloudflare Blog
AWS News Blog
AWS News Blog
IT之家
IT之家
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
H
Heimdal Security Blog
I
Intezer
A
Arctic Wolf
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
W
WeLiveSecurity

吴润写字的地方

从零构建 A 股 ETF 动量轮动系统:一个量化新手的完整指南 2025 年 8 月 Digest 2025 年 7 月 Digest 2025 年 6 月 Digest 2025 年 5 月 Digest 2025 年 4 月 Digest 清明桐庐行 2025 年 3 月 Digest 2024 年终总结 换车 崇明岛一日游 夜游徐汇滨江绿地 2023 年终总结 踏春之浦康休闲公园 香港澳门行 读「投资第一课」有感 皮皮玩球 Chrome 插件推荐 Go 并发之道:并发介绍 The Night Agent 我是如何使用 ChatGPT 的 2022 年终总结 在 Ubuntu 上搭建 MinIO 2021 年终总结 Golang 不可寻址的理解 Golang 的 defer 关键字使用注意事项 恭王府 强制删除 k8s terminating 状态命名空间 PromQL 计算 CPU 使用率 Trickster 使用 奥森的向日葵 Go Modules - checksum mismatch 错误解决 CDN 使用初探 k8s 介绍 再探 798 解决 gin 路由冲突问题 wu.run 域名正式使用 GoLand 使用指南 macOS 软件推荐 2020 这一年 Python 循环列表删除元素的注意事项 Mac 下的定时任务工具:Launchctl Linux 服务器搭建 VNC 可视化桌面 Jenkins 个别 job 页面打开超时的解决方法 遇见 Aamir Khan Hexo 从 GitHub 到阿里云 『从未说出口的秘密』词云分析 768 的秋天 北戴河 Outing 飞盘记 三里屯夜景 爬虫图解:轮子哥关注了哪些人 2017-06-30 GitHub+Hexo 搭建个人网站详细教程 特朗普税改 如果有一天,苹果和微信只能选一个,你会选哪一个? About | 吴润写字的地方 Links | 吴润写字的地方 Memos | 吴润写字的地方
PromQL 如何计算变化(率)
2021-08-09 · via 吴润写字的地方

Counter(计数器) 是 Prometheus 四种指标类型(metric type)之一,该指标特点是值会一直增加,代表积累的数量。应对诸如此类的问题:一共有多少请求处理过?花了多长时间处理请求?对于 Counter,由于是单调递增的积累量,直接使用是没有太大的意义,我们更关心 Counter 指标在一段时间内的变化量,或者是变化率。

PromQL 有三个常见的函数和变化(率)相关,分别是:increase()rate()irate()

increase

increase(v range-vector),参数 v 是一个区间向量。该函数计算的结果是该区间的增长量。如:

increase(node_cpu_seconds_total{instance="172.22.21.143:9100", cpu="0", mode="idle"}[2m])

上述查询表示,主机 172.22.21.143 的第 0 个 CPU 在过去 2 分钟时间里,idle 状态所占时长为 81.05s。

需要注意的是,像 http_requests_total 这样的 Counter 指标,返回的是 http 请求总数量,该值一定是一个大于等于 0 的整数。但是使用 increase 函数后,返回一段时间的增量值,该值可能不是整数,而是一个小数,原因是如果查询区间的时间与采样时间不重合,没有办法拿到准确的值。Prometheus 的策略会根据范围内的样本点的值进行线性估算,该方法学名是线性外插(Linear Exrapolation),就可能会产生小数。该策略不仅用于 increase 函数,还用于 delta 和 rate 函数。

rate

rate(v range-vector),可以直接计算区间向量在时间窗口内平均变化率。对于快速变化的 Counter,如果使用 rate,因为其计算的是平均变化率,很容易把峰值削平。除非我们把时间间隔设置的足够小,才能够减弱这种效应。

irate

irate(v range-vector),同样用于计算区间向量的变化率,但是其表示的是瞬时增长率。会取最后两个样本值计算瞬时变化率。所以相比较 rate 具有更高的灵敏度。

参考