All Implemented Interfaces:
DataPoint, DistributionDataPoint, TimerApi, io.prometheus.metrics.model.registry.Collector

Histogram metric. Example usage:

 Histogram histogram = Histogram.builder()
         .name("http_request_duration_seconds")
         .help("HTTP request service time in seconds")
         .unit(SECONDS)
         .labelNames("method", "path", "status_code")
         .register();

 long start = System.nanoTime();
 // do something
 histogram.labelValues("GET", "/", "200").observe(Unit.nanosToSeconds(System.nanoTime() - start));
 
Prometheus supports two internal representations of histograms:
  1. Classic Histograms have a fixed number of buckets with fixed bucket boundaries.
  2. Native Histograms have an infinite number of buckets with a dynamic resolution. Prometheus native histograms are the same as OpenTelemetry's exponential histograms.
By default, a histogram maintains both representations, i.e. the example above will maintain a classic histogram representation with Prometheus' default bucket boundaries as well as native histogram representation. Which representation is used depends on the exposition format, i.e. which content type the Prometheus server accepts when scraping. Exposition format "Text" exposes the classic histogram, exposition format "Protobuf" exposes both representations. This is great for migrating from classic histograms to native histograms.

If you want the classic representation only, use Histogram.Builder.classicOnly. If you want the native representation only, use Histogram.Builder.nativeOnly.