0

我有一个基本的直方图,可以测量一些虚拟持续时间:

    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. 我希望值是 1,我在源代码中做错了什么?为什么所有值都是 2?
  2. 如何将存储桶设置为使用范围,而不是 <=?

我看到了这个答案,但我不明白解决方案

提前致谢!

4

2 回答 2

2

我希望值是 1,我在源代码中做错了什么?为什么所有值都是 2?

你观察了两次。如果你正在使用observeDuration,你也不需要observe.

如何将存储桶设置为使用范围,而不是 <=?

你不能,这就是人们histogram_quantile期望的桶的样子。

于 2021-06-16T09:26:05.980 回答
0

我认为您可以实现这一目标的一种方法是通过正则表达式。例如,

le=~"([1-9]+)\\..*"

会给你所有大于 0.9999 的值

于 2021-10-14T12:54:44.940 回答