Class Histogram.Child
- java.lang.Object
-
- io.prometheus.client.Histogram.Child
-
- Enclosing class:
- Histogram
public static class Histogram.Child extends java.lang.Object
The value of a single Histogram.Warning: References to a Child become invalid after using
SimpleCollector.remove(java.lang.String...)
orSimpleCollector.clear()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Histogram.Child.Value
-
Field Summary
Fields Modifier and Type Field Description private long
created
private DoubleAdder[]
cumulativeCounts
private java.util.ArrayList<java.util.concurrent.atomic.AtomicReference<Exemplar>>
exemplars
private HistogramExemplarSampler
exemplarSampler
private java.lang.Boolean
exemplarsEnabled
private DoubleAdder
sum
private double[]
upperBounds
-
Constructor Summary
Constructors Modifier Constructor Description private
Child(double[] buckets, java.lang.Boolean exemplarsEnabled, HistogramExemplarSampler exemplarSampler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Histogram.Child.Value
get()
Get the value of the Histogram.void
observe(double amt)
Observe the given amount.void
observeWithExemplar(double amt, java.lang.String... exemplarLabels)
Likeobserve(double)
, but additionally creates an exemplar.void
observeWithExemplar(double amt, java.util.Map<java.lang.String,java.lang.String> exemplarLabels)
LikeobserveWithExemplar(double, String...)
, but the exemplar labels are passed as aMap
.private Exemplar
sampleNextExemplar(double amt, double bucketFrom, double bucketTo, Exemplar prev)
Histogram.Timer
startTimer()
Start a timer to track a duration.double
time(java.lang.Runnable timeable)
Executes runnable code (e.g.<E> E
time(java.util.concurrent.Callable<E> timeable)
Executes callable code (e.g.double
timeWithExemplar(java.lang.Runnable timeable, java.lang.String... exemplarLabels)
Liketime(Runnable)
, but additionally create an exemplar.double
timeWithExemplar(java.lang.Runnable timeable, java.util.Map<java.lang.String,java.lang.String> exemplarLabels)
Liketime(Runnable)
, but additionally create an exemplar.<E> E
timeWithExemplar(java.util.concurrent.Callable<E> timeable, java.lang.String... exemplarLabels)
Liketime(Callable)
, but additionally create an exemplar.<E> E
timeWithExemplar(java.util.concurrent.Callable<E> timeable, java.util.Map<java.lang.String,java.lang.String> exemplarLabels)
Liketime(Callable)
, but additionally create an exemplar.private void
updateExemplar(double amt, int i, Exemplar userProvidedExemplar)
-
-
-
Field Detail
-
exemplars
private final java.util.ArrayList<java.util.concurrent.atomic.AtomicReference<Exemplar>> exemplars
-
exemplarsEnabled
private final java.lang.Boolean exemplarsEnabled
-
exemplarSampler
private final HistogramExemplarSampler exemplarSampler
-
upperBounds
private final double[] upperBounds
-
cumulativeCounts
private final DoubleAdder[] cumulativeCounts
-
sum
private final DoubleAdder sum
-
created
private final long created
-
-
Constructor Detail
-
Child
private Child(double[] buckets, java.lang.Boolean exemplarsEnabled, HistogramExemplarSampler exemplarSampler)
-
-
Method Detail
-
time
public double time(java.lang.Runnable timeable)
Executes runnable code (e.g. a Java 8 Lambda) and observes a duration of how long it took to run.- Parameters:
timeable
- Code that is being timed- Returns:
- Measured duration in seconds for timeable to complete.
-
timeWithExemplar
public double timeWithExemplar(java.lang.Runnable timeable, java.lang.String... exemplarLabels)
Liketime(Runnable)
, but additionally create an exemplar.See
observeWithExemplar(double, String...)
for documentation on theexemplarLabels
parameter.
-
timeWithExemplar
public double timeWithExemplar(java.lang.Runnable timeable, java.util.Map<java.lang.String,java.lang.String> exemplarLabels)
Liketime(Runnable)
, but additionally create an exemplar.See
observeWithExemplar(double, Map)
for documentation on theexemplarLabels
parameter.
-
time
public <E> E time(java.util.concurrent.Callable<E> timeable)
Executes callable code (e.g. a Java 8 Lambda) and observes a duration of how long it took to run.- Parameters:
timeable
- Code that is being timed- Returns:
- Result returned by callable.
-
timeWithExemplar
public <E> E timeWithExemplar(java.util.concurrent.Callable<E> timeable, java.lang.String... exemplarLabels)
Liketime(Callable)
, but additionally create an exemplar.See
observeWithExemplar(double, String...)
for documentation on theexemplarLabels
parameter.
-
timeWithExemplar
public <E> E timeWithExemplar(java.util.concurrent.Callable<E> timeable, java.util.Map<java.lang.String,java.lang.String> exemplarLabels)
Liketime(Callable)
, but additionally create an exemplar.See
observeWithExemplar(double, Map)
for documentation on theexemplarLabels
parameter.
-
observe
public void observe(double amt)
Observe the given amount.- Parameters:
amt
- in most cases amt should be >= 0. Negative values are supported, but you should read https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations for implications and alternatives.
-
observeWithExemplar
public void observeWithExemplar(double amt, java.lang.String... exemplarLabels)
Likeobserve(double)
, but additionally creates an exemplar.This exemplar takes precedence over any exemplar returned by the
HistogramExemplarSampler
configured inExemplarConfig
.The exemplar will have
amt
as the value,System.currentTimeMillis()
as the timestamp, and the specified labels.- Parameters:
amt
- same as inobserve(double)
(double)}exemplarLabels
- list of name/value pairs, as documented inExemplar(double, String...)
. A commonly used name is"trace_id"
. CallingobserveWithExemplar(amt)
means that an exemplar without labels is created. CallingobserveWithExemplar(amt, (String[]) null)
is equivalent to callingobserve(amt)
.
-
observeWithExemplar
public void observeWithExemplar(double amt, java.util.Map<java.lang.String,java.lang.String> exemplarLabels)
LikeobserveWithExemplar(double, String...)
, but the exemplar labels are passed as aMap
.
-
updateExemplar
private void updateExemplar(double amt, int i, Exemplar userProvidedExemplar)
-
sampleNextExemplar
private Exemplar sampleNextExemplar(double amt, double bucketFrom, double bucketTo, Exemplar prev)
-
startTimer
public Histogram.Timer startTimer()
Start a timer to track a duration.Call
Histogram.Timer.observeDuration()
at the end of what you want to measure the duration of.
-
get
public Histogram.Child.Value get()
Get the value of the Histogram.Warning: The definition of
Histogram.Child.Value
is subject to change.
-
-