具有范围的 Prometheus 直方图桶
Prometheus histogram buckets with ranges
我有一个基本直方图可以测量一些虚拟持续时间:
Histogram histogram = Histogram.build().name(name).help((String) metricData.get(HELP)).register(registry);
Histogram.Timer timer = histogram.startTimer();
logger.info("Sleeps for 1 milli");
Thread.sleep(1);
histogram.observe(timer.observeDuration());
我的 Prometheus 直方图如下所示:
HELP myJob_histogram_no_buckets_test histogram with some info about something
TYPE myJob_histogram_no_buckets_test histogram
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.005"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.01"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.025"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.05"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.075"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.1"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.25"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.75"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="1"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="2.5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="7.5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="10"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="+Inf"} 2
myJob_histogram_no_buckets_test_sum{instance="",job="latrodectus"} 0.006341000000000001
myJob_histogram_no_buckets_test_count{instance="",job="latrodectus"} 2
我明白为什么我所有的桶值都增加了,但我不明白两件事:
- 我期望值是 1,我在源代码中做错了什么?为什么所有值都是 2?
- 如何将存储桶设置为使用范围,而不是 <=?
我看到了这个但是我不明白解决方案
提前致谢!
I expected the values to be 1, what am I doing wrong in my source code? why all values are 2?
您观察了两次。如果您使用 observeDuration
,则不需要 observe
.
How can I set the buckets to use ranges, instead of <=?
你不能,这就是 histogram_quantile
期望桶的样子。
我认为实现此目的的一种方法是通过正则表达式。例如,
le=~"([1-9]+)\..*"
将为您提供所有大于 0.9999 的值
我有一个基本直方图可以测量一些虚拟持续时间:
Histogram histogram = Histogram.build().name(name).help((String) metricData.get(HELP)).register(registry);
Histogram.Timer timer = histogram.startTimer();
logger.info("Sleeps for 1 milli");
Thread.sleep(1);
histogram.observe(timer.observeDuration());
我的 Prometheus 直方图如下所示:
HELP myJob_histogram_no_buckets_test histogram with some info about something
TYPE myJob_histogram_no_buckets_test histogram
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.005"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.01"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.025"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.05"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.075"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.1"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.25"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="0.75"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="1"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="2.5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="7.5"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="10"} 2
myJob_histogram_no_buckets_test_bucket{instance="",job="myJob",le="+Inf"} 2
myJob_histogram_no_buckets_test_sum{instance="",job="latrodectus"} 0.006341000000000001
myJob_histogram_no_buckets_test_count{instance="",job="latrodectus"} 2
我明白为什么我所有的桶值都增加了,但我不明白两件事:
- 我期望值是 1,我在源代码中做错了什么?为什么所有值都是 2?
- 如何将存储桶设置为使用范围,而不是 <=?
我看到了这个
提前致谢!
I expected the values to be 1, what am I doing wrong in my source code? why all values are 2?
您观察了两次。如果您使用 observeDuration
,则不需要 observe
.
How can I set the buckets to use ranges, instead of <=?
你不能,这就是 histogram_quantile
期望桶的样子。
我认为实现此目的的一种方法是通过正则表达式。例如,
le=~"([1-9]+)\..*"
将为您提供所有大于 0.9999 的值