Package io.prometheus.client
Class Gauge.Child
- java.lang.Object
-
- io.prometheus.client.Gauge.Child
-
- Enclosing class:
- Gauge
public static class Gauge.Child extends java.lang.Object
The value of a single Gauge.Warning: References to a Child become invalid after using
SimpleCollector.remove(java.lang.String...)
orSimpleCollector.clear()
,
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static Gauge.TimeProvider
timeProvider
private DoubleAdder
value
-
Constructor Summary
Constructors Constructor Description Child()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dec()
Decrement the gauge by 1.void
dec(double amt)
Decrement the gauge by the given amount.double
get()
Get the value of the gauge.void
inc()
Increment the gauge by 1.void
inc(double amt)
Increment the gauge by the given amount.void
set(double val)
Set the gauge to the given value.void
setToCurrentTime()
Set the gauge to the current unixtime.double
setToTime(java.lang.Runnable timeable)
Executes runnable code (e.g.<E> E
setToTime(java.util.concurrent.Callable<E> timeable)
Executes callable code (e.g.Gauge.Timer
startTimer()
Start a timer to track a duration.
-
-
-
Field Detail
-
value
private final DoubleAdder value
-
timeProvider
static Gauge.TimeProvider timeProvider
-
-
Method Detail
-
inc
public void inc()
Increment the gauge by 1.
-
inc
public void inc(double amt)
Increment the gauge by the given amount.
-
dec
public void dec()
Decrement the gauge by 1.
-
dec
public void dec(double amt)
Decrement the gauge by the given amount.
-
set
public void set(double val)
Set the gauge to the given value.
-
setToCurrentTime
public void setToCurrentTime()
Set the gauge to the current unixtime.
-
startTimer
public Gauge.Timer startTimer()
Start a timer to track a duration.Call
Gauge.Timer.setDuration()
at the end of what you want to measure the duration of.This is primarily useful for tracking the durations of major steps of batch jobs, which are then pushed to a PushGateway. For tracking other durations/latencies you should usually use a
Summary
.
-
setToTime
public double setToTime(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.
-
setToTime
public <E> E setToTime(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.
-
get
public double get()
Get the value of the gauge.
-
-