public static final class PolledMeter.Builder extends TagsBuilder<PolledMeter.Builder>
extraTags
Modifier and Type | Method and Description |
---|---|
<T extends java.lang.Number> |
monitorMonotonicCounter(T number)
Poll the value of the provided
Number and update a counter with the delta
since the last time the value was sampled. |
<T> T |
monitorMonotonicCounter(T obj,
java.util.function.ToLongFunction<T> f)
Map a monotonically increasing long or int value to a counter.
|
<T extends java.util.Collection<?>> |
monitorSize(T collection)
Poll the value of the provided
Collection . |
<T extends java.util.Map<?,?>> |
monitorSize(T map)
Poll the value of the provided
Map . |
<T extends java.lang.Number> |
monitorValue(T number)
Poll the value of the provided
Number . |
<T> T |
monitorValue(T obj,
java.util.function.ToDoubleFunction<T> f)
Poll by executing
f(obj) and reporting the returned value. |
PolledMeter.Builder |
scheduleOn(java.util.concurrent.ScheduledExecutorService executor)
Set the executor to be used for polling the value.
|
PolledMeter.Builder |
withDelay(java.time.Duration delay)
Set the delay at which the value should be refreshed.
|
public PolledMeter.Builder scheduleOn(java.util.concurrent.ScheduledExecutorService executor)
public PolledMeter.Builder withDelay(java.time.Duration delay)
RegistryConfig.gaugePollingFrequency()
public <T extends java.lang.Number> T monitorValue(T number)
Number
. The implementation provided must
be thread safe. The most common usages of this are to monitor instances of
AtomicInteger
or AtomicLong
.number
- Thread-safe implementation of Number
used to access the value.public <T> T monitorValue(T obj, java.util.function.ToDoubleFunction<T> f)
f(obj)
and reporting the returned value. The provided
function must be thread safe and cheap to execute. Expensive operations, including
any IO or network calls, should not be performed inline unless using a custom
executor by calling scheduleOn(ScheduledExecutorService)
. Assume that the
function will be called frequently and may be called concurrently.
A weak reference will be kept to obj
so that monitoring the object will
not prevent garbage collection. The meter will go away when obj
is collected.
To explicitly disable polling call PolledMeter.remove(Registry, Id)
with the same id used with
this builder.
obj
- Object used to compute a value.f
- Function that is applied on the value for the number.public <T extends java.lang.Number> T monitorMonotonicCounter(T number)
Number
and update a counter with the delta
since the last time the value was sampled. The implementation provided must
be thread safe. The most common usages of this are to monitor instances of
AtomicInteger
,
AtomicLong
, or
LongAdder
. For more information see
monitorMonotonicCounter(Object, ToLongFunction)
.number
- Thread-safe implementation of Number
used to access the value.public <T> T monitorMonotonicCounter(T obj, java.util.function.ToLongFunction<T> f)
Example monotonic counters provided by the JDK:
ThreadPoolExecutor.getCompletedTaskCount()
java.lang.management.GarbageCollectorMXBean#getCollectionCount()
Example usage:
Registry registry = ... MonotonicCounter.using(registry) .withName("pool.completedTasks") .monitorMonotonicCounter(executor, ThreadPoolExecutor::getCompletedTaskCount);
The value is polled by executing f(obj)
and a counter will be updated with
the delta since the last time the value was sampled. The provided function must be
thread safe and cheap to execute. Expensive operations, including any IO or network
calls, should not be performed inline unless using a custom executor by calling
scheduleOn(ScheduledExecutorService)
. Assume that the function will be called
frequently and may be called concurrently.
A weak reference will be kept to obj
so that monitoring the object will
not prevent garbage collection. The meter will go away when obj
is collected.
To explicitly disable polling call PolledMeter.remove(Registry, Id)
with the same id used with
this builder.
obj
- Object used to compute a value.f
- Function that is applied on the value for the number.public <T extends java.util.Collection<?>> T monitorSize(T collection)
Collection
. The implementation provided must
be thread safe. Keep in mind that computing the size can be an expensive operation
for some collection types.collection
- Thread-safe implementation of Collection
.public <T extends java.util.Map<?,?>> T monitorSize(T map)
Map
. The implementation provided must
be thread safe. Keep in mind that computing the size can be an expensive operation
for some map types.map
- Thread-safe implementation of Map
.