如果仪表可以充当计数器,为什么普罗米修斯既有计数器又有仪表?
问题说明
在确定Counter
和Gauge
之间时,
They seem to cover overlapping use cases: you could use a Gauge that only ever increases. So why even create the Counter metric type in the first place? Why don't you simply use Gauges for both?
正确答案
从概念上讲,仪表和计数器的目的不同
From a conceptual point of view, gauge and counter have different purposes
- 量规通常代表一种状态,通常是为了检测饱和度.
- 计数器的绝对值不是很有意义,真正的目的是使用
irate/rate()
,increase()
...
之类的函数来计算演化(通常是利用率).
- a gauge typically represent a state, usually with the purpose of detecting saturation.
- the absolute value of a counter is not really meaningful, the real purpose is rather to compute an evolution (usually a utilization) with functions like
irate/rate()
,increase()
...
这些演化操作需要可靠地计算量规无法达到的增长,因为您需要检测该值的重置.
Those evolution operations requires a reliable computation of the increase that you could not achieve with a gauge because you need to detect resets of the value.
从技术上讲,计数器具有两个重要属性:
Technically, a counter has two important properties:
- 它总是从0开始
- 它总是增加(即代码中增加)
如果应用程序在两次Prometheus刮擦之间重新启动,则第二个刮擦的值可能小于前一个刮擦的值,并且可以恢复增加的值(之所以这样,是因为您总是会在最后一个刮擦和重置之间松开增加的值).
If the application restarts between two Prometheus scrapes, the value of the second scrape in likely to be less than the previous scrape and the increase can be recovered (somewhat because you'll always loose the increase between the last scrape and the reset).
一种简单的算法来计算从t1到t2的废料之间的计数增加:
A simple algorithm to compute the increase of counter between scrapes from t1 to t2 is:
- 如果
counter(t2) >= counter(t1)
,则increase=counter(t2)-counter(t1)
- 如果
counter(2) < counter(t1)
然后increase=counter(t2)
- if
counter(t2) >= counter(t1)
thenincrease=counter(t2)-counter(t1)
- if
counter(2) < counter(t1)
thenincrease=counter(t2)
结论是,从技术角度来看,您可以使用仪表而不是计数器,前提是您在启动时将其重置为0,并且仅将其递增,但是任何违反合同的行为都将导致错误的值.
As a conclusion, from a technical point of view, you can use a gauge instead of a counter provided you reset it to 0 at startup and only increment it but any violation of contract will lead to wrong values.
作为旁注,我还希望计数器实现使用无符号整数表示,而gauge则宁愿使用浮点表示.这对代码有一些小的影响,例如能够自动溢出到0的能力以及更好地支持当前cpus上的原子操作.
As a side note, I also expect a counter implementation to use unsigned integer representation while gauge will rather use a floating point representation. This has some minor impacts on the code such as the ability to overflow to 0 automatically and better support for atomic operations on current cpus.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgahgf
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20