prometheus.NewHistogram() api 直方图指标类型
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 secconds"
// Cumulative bucket upper bounds
Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2,5, 5, 10}
})
requestDurations.Observe(0.42)
Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2,5, 5, 10}
是什么意思?
requestDurations.Observe(0.42)
是什么意思?
如软件包文档所述:
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.
直方图对桶中的观测值进行计数。通过此声明,您可以声明上限为 0.05、0.1、0.25、...、5、10、+inf 的桶。每个观察值都将计入这些桶之一。例如,Observe(0.42)
将增加上限为 >=0.5 的桶。
我建议您阅读内容广泛的在线文档,例如Histograms
直方图由值桶表示。
第一个命令通过上限定义直方图的桶:值 <= 0.05、<= 0.1 等。
第二个命令,通过递增 <= 0.5 桶(以及所有更大的桶)将观测值 0.42 添加到直方图。
使用 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 secconds"
// Cumulative bucket upper bounds
Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2,5, 5, 10}
})
requestDurations.Observe(0.42)
Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2,5, 5, 10}
是什么意思?requestDurations.Observe(0.42)
是什么意思?
如软件包文档所述:
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.
直方图对桶中的观测值进行计数。通过此声明,您可以声明上限为 0.05、0.1、0.25、...、5、10、+inf 的桶。每个观察值都将计入这些桶之一。例如,Observe(0.42)
将增加上限为 >=0.5 的桶。
我建议您阅读内容广泛的在线文档,例如Histograms
直方图由值桶表示。
第一个命令通过上限定义直方图的桶:值 <= 0.05、<= 0.1 等。
第二个命令,通过递增 <= 0.5 桶(以及所有更大的桶)将观测值 0.42 添加到直方图。