I have a basic histogram that measures some dummy duration:
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());
My Prometheus histograms looks as follows:
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
I understand why all my buckets values Increased, but I don't understand two things:
I saw this answer but I don't understand the solution
Thanks in advance!
I expected the values to be 1, what am I doing wrong in my source code? why all values are 2?
You observed twice. If you're using observeDuration
you don't also need observe
.
How can I set the buckets to use ranges, instead of <=?
You can't, this is how histogram_quantile
expects the buckets to be.