官方网站文档解读
irate和rate用于计算固定时间间隔内指标的变化率。 但是,这些计算方法不同。 irate采用指定时间范围内最近的两个据点计算速率,rate采用指定时间范围内的所有数据点计算一系列速率,并以平均值作为结果。
因此,根据官方网站的文件,irate适合快速变化的计数器(counter ),rate适合缓慢变化的计数器(counter )。
从以上算法也可以看出,对于急剧变化的计数器,如果使用rate,由于使用平均值,很容易使峰值平坦。 我们只要不把时间间隔设定得足够小,就可以减弱这个效果。
考试
用grafana进行实验,制作测试用的dashboard,分别用irate和rate监测CPU使用率指标。 时间间隔分别为10m、5m、2m、1m。 其中,10分钟间隔的公式如下:
sum (process _ CPU _ seconds _ total [ 10m ] ) 100
rate (process _ CPU _ seconds _ total [ 10m ] ) 100
下图是10分钟间隔的结果。 可以看到,irate的曲线相对曲折,而rate的曲线相对平缓。
下图是5分钟间隔的结果。
下图是2分钟间隔的结果,两条曲线重叠。
下图显示了每分钟一次的结果,没有数据。 无法找到要在此时间间隔内计算的数据集,因此没有数据:
附件:官方网站文档
irate () )
irate(vrange-vector )。 calculatestheper-secondinstantrateofincreaseofthetimeseriesintherangevector.thisisbasedonthelastwodatapoints.breaksinmon sduetotargetrestarts ) are automatically adjusted for。
thefollowingexampleexpressionreturnstheper-secondrateofhttprequestslookingupto5minutesbackforthetwomostrecentdatapoints,pepoints
irate(http_requests_total ) job='API-server'}[5m]
irateshouldonlybeusedwhengraphingvolatile,fast-moving counters.userateforalertsandslow-moving counters,asbriefchangesion
notethatwhencombiningirate (withanaggregationoperator ) e.g.sum ) orafunctionaggregatingovertime ) anyfunctionending al then aggregate. Otherwise irate ) cannotdetectcounterresetswhenyourtargetrestarts。
rate () )
rate(vrange-vector )。 calculatestheper-secondaveragerateofincreaseofthetimeseriesintherangevector.breaksinmonotonicity thecalculationextrapolatestotheendsofthetimerange,allowingformissedscrapesorimperfectalignmentofscrapecycleswiththerange ' stherange
thefollowingexampleexpressionreturnstheper-secondrateofhttprequestsasmeasuredoverthelast5minutes,pertimeseriesintherangeveer
rate(http_requests_total ) job='API-server'}[5m]
rateshouldonlybeusedwithcounters.itisbestsuitedforalerting,andforgraphingofslow-moving counters。
notethatwhencombiningrate (withanaggregationoperator ) e.g.sum ) orafunctionaggregatingovertime ) anyfunctionending alwabertion then aggregate. Otherwise rate ) cannotdetectcounterresetswhenyourtargetrestarts。
----------------
作者:东东~
来源: CSDN
原文: https://blog.csdn.net/palet/article/details/82763695
声明:本文为博主原创文章。 转载请附上博文链接!
转载于:https://www.cn blogs.com/yx88/p/11270163.html