Class Histogram
java.lang.Object
io.prometheus.metrics.core.metrics.Metric
io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
io.prometheus.metrics.core.metrics.Histogram
- All Implemented Interfaces:
DataPoint
,DistributionDataPoint
,TimerApi
,io.prometheus.metrics.model.registry.Collector
Histogram metric. Example usage:
Histogram histogram = Histogram.newBuilder()
.withName("http_request_duration_seconds")
.withHelp("HTTP request service time in seconds")
.withUnit(SECONDS)
.withLabelNames("method", "path", "status_code")
.register();
long start = System.nanoTime();
// do something
histogram.withLabelValues("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 -
Field Summary
Fields inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
labelNames
Fields inherited from class io.prometheus.metrics.core.metrics.Metric
constLabels
-
Method Summary
Modifier and TypeMethodDescriptionio.prometheus.metrics.model.snapshots.HistogramSnapshot
collect()
protected io.prometheus.metrics.model.snapshots.HistogramSnapshot
collect
(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<Histogram.DataPoint> metricData) labels and metricData have the same size.protected <T> T
getConfigProperty
(io.prometheus.metrics.config.MetricsProperties[] properties, Function<io.prometheus.metrics.config.MetricsProperties, T> getter) protected io.prometheus.metrics.config.MetricsProperties[]
getMetricProperties
(io.prometheus.metrics.core.metrics.StatefulMetric.Builder builder, io.prometheus.metrics.config.PrometheusProperties prometheusProperties) protected Histogram.DataPoint
protected boolean
static Histogram.Builder
static Histogram.Builder
newBuilder
(io.prometheus.metrics.config.PrometheusProperties config) protected Histogram.DataPoint
void
observe
(double amount) Observevalue
.void
observeWithExemplar
(double amount, io.prometheus.metrics.model.snapshots.Labels labels) Observevalue
, and create a custom exemplar with the given labels.void
withLabelValues
(String... labelValues) Methods inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
getMetadata
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.prometheus.metrics.model.registry.Collector
collect, getName
Methods inherited from interface io.prometheus.metrics.core.datapoints.DistributionDataPoint
startTimer
Methods inherited from interface io.prometheus.metrics.core.datapoints.TimerApi
time, time, timeChecked
-
Method Details
-
observe
Observevalue
.- Specified by:
observe
in interfaceDistributionDataPoint
-
observeWithExemplar
Observevalue
, and create a custom exemplar with the given labels.- Specified by:
observeWithExemplar
in interfaceDistributionDataPoint
-
isExemplarsEnabled
-
collect
- Specified by:
collect
in interfaceio.prometheus.metrics.model.registry.Collector
-
collect
protected io.prometheus.metrics.model.snapshots.HistogramSnapshot collect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<Histogram.DataPoint> metricData) labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i). -
newDataPoint
-
newBuilder
-
newBuilder
public static Histogram.Builder newBuilder(io.prometheus.metrics.config.PrometheusProperties config) -
withLabelValues
-
remove
-
getNoLabels
-
getMetricProperties
protected io.prometheus.metrics.config.MetricsProperties[] getMetricProperties(io.prometheus.metrics.core.metrics.StatefulMetric.Builder builder, io.prometheus.metrics.config.PrometheusProperties prometheusProperties) -
getConfigProperty
protected <T> T getConfigProperty(io.prometheus.metrics.config.MetricsProperties[] properties, Function<io.prometheus.metrics.config.MetricsProperties, T> getter)
-