prometheus.NewHistogram() 是用于创建直方图(histogram)指标类型的 API。

huangapple go评论93阅读模式
英文:

prometheus.NewHistogram() api for histogram metric type

问题

使用github.com/prometheus/client_golang/prometheus库来为GO应用程序进行指标仪表化:

在下面的代码中:

requestDurations := prometheus.NewHistogram(prometheus.HistogramOpts{
     Name: "http_request_duration_seconds",
     Help: "A Histogram of the http request duration in seconds",

     // Cumulative bucket upper bounds
     Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2, 5, 5, 10}
})

requestDurations.Observe(0.42)
  1. Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2, 5, 5, 10}表示什么?

  2. requestDurations.Observe(0.42)表示什么?

英文:

Using github.com/prometheus/client_golang/prometheus library to instrument GO app, for metrics:

In the below code:

requestDurations := prometheus.NewHistogram(prometheus.HistogramOpts{
     Name: "http_request_duration_seconds"
     Help: "A Histogram of the http request duration in secconds"

     // Cumulative bucket upper bounds
     Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2,5, 5, 10}
})

requestDurations.Observe(0.42)

  1. What does Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2,5, 5, 10} imply?

  2. What does requestDurations.Observe(0.42) imply?

答案1

得分: 1

根据包的文档说明:

Buckets定义了观测值被计数的桶。切片中的每个元素都是一个桶的上限(包含)。这些值必须按严格递增的顺序排序。不需要添加一个具有+Inf边界的最高桶,它将被隐式添加。默认值是DefBuckets。

直方图会将观测值计数到各个桶中。通过这个声明,你声明了上限为0.05、0.1、0.25、...、5、10和+inf的桶。每个观测值将被计数到这些桶中的一个。例如,Observe(0.42)会增加那些上限大于等于0.5的桶的计数。

英文:

As the package documentation states:
> Buckets defines the buckets into which observations are counted. Each
element in the slice is the upper inclusive bound of a bucket. The
values must be sorted in strictly increasing order. There is no need
to add a highest bucket with +Inf bound, it will be added
implicitly. The default value is DefBuckets.

Histogram counts observations in buckets. With this declaration, you declare buckets with upper limits of 0.05, 0.1, 0.25, ..., 5, 10, +inf. Each observation will be counted in one of these buckets. For instance, the Observe(0.42) will increment the buckets whose upper limits are >=0.5.

huangapple
  • 本文由 发表于 2021年10月26日 10:51:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/69716938.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定