• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

如果仪表可以充当计数器,为什么普罗米修斯既有计数器又有仪表?

用户头像
it1352
帮助1

问题说明

在确定CounterGauge之间时,

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?

正确答案

#1

从概念上讲,仪表和计数器的目的不同

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:

  1. 它总是从0开始
  2. 它总是增加(即代码中增加)

如果应用程序在两次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) then increase=counter(t2)-counter(t1)
  • if counter(2) < counter(t1)then increase=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
系列文章
更多 icon
同类精品
更多 icon
继续加载