Class Histogram
- All Implemented Interfaces:
DataPoint, DistributionDataPoint, TimerApi, Collector
public class Histogram
extends StatefulMetric<DistributionDataPoint, Histogram.DataPoint>
implements DistributionDataPoint
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:
- Classic Histograms have a fixed number of buckets with fixed bucket boundaries.
- Native Histograms have an infinite number of buckets with a dynamic resolution. Prometheus native histograms are the same as OpenTelemetry's exponential histograms.
If you want the classic representation only, use Histogram.Builder.classicOnly. If you
want the native representation only, use Histogram.Builder.nativeOnly.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Histogram.Builderbuilder()static Histogram.Builderbuilder(PrometheusProperties config) collect()Called when the Prometheus server scrapes metrics.longgetCount()Get the count of observations.doublegetSum()Get the sum of all observed values.voidobserve(double amount) Observevalue.voidobserveWithExemplar(double amount, Labels labels) Observevalue, and create a custom exemplar with the given labels.Methods inherited from class StatefulMetric
clear, initLabelValues, labelValues, remove, removeIfMethods inherited from class MetricWithFixedMetadata
getPrometheusNameMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DistributionDataPoint
startTimerMethods inherited from interface TimerApi
time, time, timeChecked
-
Method Details
-
getSum
Description copied from interface:DistributionDataPointGet the sum of all observed values.- Specified by:
getSumin interfaceDistributionDataPoint
-
getCount
Description copied from interface:DistributionDataPointGet the count of observations.- Specified by:
getCountin interfaceDistributionDataPoint
-
observe
Description copied from interface:DistributionDataPointObservevalue.- Specified by:
observein interfaceDistributionDataPoint
-
observeWithExemplar
Description copied from interface:DistributionDataPointObservevalue, and create a custom exemplar with the given labels.- Specified by:
observeWithExemplarin interfaceDistributionDataPoint
-
collect
Description copied from interface:CollectorCalled when the Prometheus server scrapes metrics.- Specified by:
collectin interfaceCollector- Overrides:
collectin classStatefulMetric<DistributionDataPoint, Histogram.DataPoint>
-
builder
-
builder
-