prometheus 监控磁盘容量:深入浅出监控神器Prometheus
prometheus 监控磁盘容量:深入浅出监控神器Prometheus我用histogram_quantile函数计算下:计算结果是1.25,其实已经不对了。MyHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "my_histogram_bucket" Help: "自定义histogram" Buckets: []float64{0 2.5 5 7.5 10} // 需要指定桶 })如果这样的话,所有指标都会直接进入到第一个桶,即0到2.5这个桶,如果我要计算中位数,那么这个中位数按照数学公式来算的话,肯定是在0到2.之间的,而且肯定是0.3到0.5之间。histogram_quantile(0.5 go_gc_pauses_seconds_total_bucket)分享之前和同事一起发现的坑:在刚刚写的自定
但是这样直接的相加太笼统抽象了,可以配合by和without函数在sum的时候,基于某些标签分组,类似SQL中的group by
例如,我可以根据请求接口标签分组:这样拿到的就是具体接口的QPS:
sum(rate(demo_api_request_duration_seconds_count{job="demo" method="GET" status="200"}[5m])) by(path)
也可以不根据接口路径分组:通过without指定:
sum(rate(demo_api_request_duration_seconds_count{job="demo" method="GET" status="200"}[5m])) without(path)
可以通过histogram_quantile函数做数据统计:可以用来统计百分位数:第一个参数是百分位,第二个histogram指标,这样计算出来的就是中位数,即P50
histogram_quantile(0.5 go_gc_pauses_seconds_total_bucket)
分享之前和同事一起发现的坑:
在刚刚写的自定义exporter上新增几个histogram的样本点:
MyHistogram.Observe(0.3)
MyHistogram.Observe(0.4)
MyHistogram.Observe(0.5)
histogram的桶设置:
MyHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "my_histogram_bucket"
Help: "自定义histogram"
Buckets: []float64{0 2.5 5 7.5 10} // 需要指定桶
})
如果这样的话,所有指标都会直接进入到第一个桶,即0到2.5这个桶,如果我要计算中位数,那么这个中位数按照数学公式来算的话,肯定是在0到2.之间的,而且肯定是0.3到0.5之间。
我用histogram_quantile函数计算下:计算结果是1.25,其实已经不对了。
histogram_quantile(0.5 my_histogram_bucket_bucket)
我在计算下P99,等于2.475:
histogram_quantile(0.99 my_histogram_bucket_bucket)