Prometheus监控:rate与irate的区别

article/2025/9/28 14:35:46

对官网文档的解读

irate和rate都会用于计算某个指标在一定时间间隔内的变化速率。但是它们的计算方法有所不同:irate取的是在指定时间范围内的最近两个数据点来算速率,而rate会取指定时间范围内所有数据点,算出一组速率,然后取平均值作为结果。

所以官网文档说:irate适合快速变化的计数器(counter),而rate适合缓慢变化的计数器(counter)。

根据以上算法我们也可以理解,对于快速变化的计数器,如果使用rate,因为使用了平均值,很容易把峰值削平。除非我们把时间间隔设置得足够小,就能够减弱这种效应。

试验

用grafana做了一个试验,创建一个测试的dashboard, 分别用 irate 和 rate 来监控CPU使用率指标,时间间隔分别用10m, 5m, 2m, 1m 。其中间隔为10分钟的表达式如下:

sum(irate(process_cpu_seconds_total[10m])) * 100

sum(rate(process_cpu_seconds_total[10m])) * 100

下图是间隔10分钟的结果,可以看到,irate的曲线比较曲折,而rate的曲线相对平缓:

下图是间隔5分钟的结果:

下图是间隔2分钟的结果,两个曲线重合了:

下图是间隔1分钟的结果,显示没有数据,应该是在这个时间间隔找不到一组数据来计算,所以没有数据:

 

附:官网文档

irate()

irate(v range-vector) calculates the per-second instant rate of increase of the time series in the range vector. This is based on the last two data points. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for.

The following example expression returns the per-second rate of HTTP requests looking up to 5 minutes back for the two most recent data points, per time series in the range vector:

irate(http_requests_total{job="api-server"}[5m])

irate should only be used when graphing volatile, fast-moving counters. Use rate for alerts and slow-moving counters, as brief changes in the rate can reset the FOR clause and graphs consisting entirely of rare spikes are hard to read.

Note that when combining irate() with an aggregation operator (e.g. sum()) or a function aggregating over time (any function ending in _over_time), always take a irate() first, then aggregate. Otherwise irate() cannot detect counter resets when your target restarts.

rate()

rate(v range-vector) calculates the per-second average rate of increase of the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. Also, the calculation extrapolates to the ends of the time range, allowing for missed scrapes or imperfect alignment of scrape cycles with the range's time period.

The following example expression returns the per-second rate of HTTP requests as measured over the last 5 minutes, per time series in the range vector:

rate(http_requests_total{job="api-server"}[5m])

rate should only be used with counters. It is best suited for alerting, and for graphing of slow-moving counters.

Note that when combining rate() with an aggregation operator (e.g. sum()) or a function aggregating over time (any function ending in _over_time), always take a rate() first, then aggregate. Otherwise rate() cannot detect counter resets when your target restarts.


http://chatgpt.dhexx.cn/article/a6vlRHr6.shtml

相关文章

【博客486】prometheus-----rate,irate,increase的原理

prometheus-----rate,irate,increase的原理 三者综合比较 这三个函数接受的都是 Range Vector,返回的是 Instant Vector,比较常用。 区别: rate计算指定时间范围内:增量/时间范围; irate计算指…

【博客650】irate适用于绘制细粒度灵敏图,但警惕用于告警

irate适用于绘制细粒度灵敏图,但警惕用于告警 1、irate解析 作用: irate(v range-vector) 函数用于计算区间向量的增长率,但是其反应出的是瞬时增长率。 原理: irate 函数是通过区间向量中最后两个两本数据来计算区间向量的增长…

git查看用户名和密码

一、查看 查看用户名 :git config user.name 查看密码: git config user.password 查看邮箱:git config user.email 查看配置信息: $ git config --list 二、修改 修改用户名 git config --global user.name “xxxx(新的用户名)”…

Linux中git保存用户名密码

Linux下命令行使用git,每次操作都要输入用户名和密码很麻烦,可以通过配置保存用户名和密码。 进入到git项目的根目录下,打开.git目录下的config文件 cd .git vim config添加如下内容 [credential]helper store:wq保存退出 执行上述操作之…

git设置单个仓库用户名以及密码

有些时候我们的服务器可能要部署多个git仓库,不同git仓库的用户名以及密码都是不一样的,此时需要我们设置单个仓库的用户名以及密码。 1.git设置用户名以及邮箱 命令如下: git config user.name "userName" //你的用户名 …

git 修改用户名和密码

windows 在控制面板修改凭证就可以进行修改用户名密码。 Linux 执行vim ~/.git-credentials,可以看到被保存的账号密码,删掉、修改或新增都可以! eg:http://账号:密码git仓库http地址或用https://账号:密码git仓库http地址 h…

mac下git设置用户名密码

设置用户名和邮箱 git config --global user.name [username] git config --global user.email [email] 查看用户名和邮箱 git config --global user.name git config --global user.email 查看配置文件 git config --list 编辑配置文件 vi .gitconfig sourcetree中的…

linux 分配git用户名和密码,配置Git记住用户名密码的俩种方法

前言 相信大家在使用github过程中,也有这情况,总是让大家输入烦人的用户名,密码,浪费时间。下面这俩种办法也是网上找来的,我做了些整合,避免大家走入当时跟我一样的坑中。 方法一 1.1创建文件储存git用户名…

git重新设置用户名密码

设置密码 我们输入git config --global user.name "youname"设置密码,在输入git config --global user.email "aaqq.com"设置邮箱

git设置用户名、密码和邮箱(全局设置)

(1)git设置用户名(如下图一): git config --global user.name Urasaki (2)git设置密码(如下图一): git config --global user.password Am100100 &#xff…

设置git账户名和密码

git config --global user.email [email] //邮箱 git config --global user.name [username] //密码查看是否配置成功 git config --list出现user.email和user.name表示配置成功

git设置账户名密码

最近新创建了一个项目,同步git代码,但是每次连接远程都要重新输入用户名密码信息,很烦,就想着怎么让他记住账号。就用了以下方法,亲测有效,分享记录下。 一. 打开当前项目下.git文件夹,找到con…

git记住用户名和密码

在使用git时,如果用的是HTTPS的方式,则每次提交,都会让输入用户名和密码,久而久之,就会感觉非常麻烦,那么该如何解决呢? 方式一:使用SSH,添加ssh key。 方式二&#xf…

git设置用户名密码(单用户和多用户)

刚换电脑重头配置git,写篇文章纪念一下。 一、前言 Git共有三个级别的config文件,分别是system、global和local。global的在$home\.gitconfig,local的在仓库目录下的.git\config。这三个级别都分别配置了用户信息,当git commit时…

JS的 execCommand 方法实现一个简单的富文本编辑器

一、document.execCommand() 从其名字上可以看出execCommand()是用来执行命令的,当一个HTML文档切换到设计模式时,document暴露 execCommand方法,该方法允许运行命令来操纵可编辑内容区域的元素。如保存文件、打开新文件、撤消、重做、剪切…

用c语言,制作一个心形彩色告白图案(附源码)

今天我们来一个好玩的&#xff0c;用c语言&#xff0c;制作一个心形彩色告白图案。 送给c语言初学者 代码&#xff1a; #include<stdio.h> #include<math.h> #include<windows.h> #include<time.h> #define u 0.1 #define v 0.053 void setcolor(uns…

ASP.NET 2.0中使用Gridview控件的高级技巧

ASP.NET 2.0中&#xff0c;新增加的gridview控件的确十分强大&#xff0c;弥补了在asp.net 1.1中&#xff0c;使用datagrid控件时的不足之处。因为在asp.net 1.1中&#xff0c;在使用datagrid时&#xff0c;很多情况下依然要编写大量的代码&#xff0c;十分不方便&#xff0c;而…

C# winform中,简单实现Listview.Subitem.BackColor.ForeColor改变字体颜色,Listview.Subitem.BackColor 改变背景

做项目的时候,客户的查询结果中要在listview中亮显查询关键字.在网上找了半天,没有合适的代码.于是就自己琢磨了一下.贴出代码,希望对大家有所帮助. 注意事项&#xff1a; 一定要把listview的OwnerDraw属性设置为True&#xff08;默认是False&#xff09;。 当设置Owner…

Button 设置ForeColor不生效问题

Button 设置ForeColor不生效问题 在C#设计界面的时候出现的一个问题&#xff0c;在将button 的属性Enable设置为False后&#xff0c;无论你设置的ForeColor为什么颜色&#xff0c;结果都只有一种颜色。 如下图&#xff1a; button1&#xff0c;属性如下&#xff1a; BackCo…