public abstract class MeterRegistry
extends java.lang.Object
MeterRegistry may be used in a reactive context. As such, implementations must not negatively impact the calling thread, e.g. it should respond immediately by avoiding IO call, deep stack recursion or any coordination.
If you register meters having the same ID multiple times, the first registration only will work and the subsequent registrations will be ignored.
Modifier and Type | Class and Description |
---|---|
class |
MeterRegistry.Config
Access to configuration options for this registry.
|
class |
MeterRegistry.More
Additional, less commonly used meter types.
|
Modifier | Constructor and Description |
---|---|
protected |
MeterRegistry(Clock clock) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all meters.
|
void |
close()
Closes this registry, releasing any resources in the process.
|
MeterRegistry.Config |
config() |
Counter |
counter(java.lang.String name,
java.lang.Iterable<Tag> tags)
Tracks a monotonically increasing value.
|
Counter |
counter(java.lang.String name,
java.lang.String... tags)
Tracks a monotonically increasing value.
|
protected abstract DistributionStatisticConfig |
defaultHistogramConfig()
Every custom registry implementation should define a default histogram expiry at a minimum:
|
Search |
find(java.lang.String name)
Initiate a search beginning with a metric name.
|
void |
forEachMeter(java.util.function.Consumer<? super Meter> consumer)
Iterate over each meter in the registry.
|
<T extends java.lang.Number> |
gauge(java.lang.String name,
java.lang.Iterable<Tag> tags,
T number)
Register a gauge that reports the value of the
Number . |
<T> T |
gauge(java.lang.String name,
java.lang.Iterable<Tag> tags,
T stateObject,
java.util.function.ToDoubleFunction<T> valueFunction)
Register a gauge that reports the value of the object after the function
valueFunction is applied. |
<T extends java.lang.Number> |
gauge(java.lang.String name,
T number)
Register a gauge that reports the value of the
Number . |
<T> T |
gauge(java.lang.String name,
T stateObject,
java.util.function.ToDoubleFunction<T> valueFunction)
Register a gauge that reports the value of the object.
|
<T extends java.util.Collection<?>> |
gaugeCollectionSize(java.lang.String name,
java.lang.Iterable<Tag> tags,
T collection)
Register a gauge that reports the size of the
Collection . |
<T extends java.util.Map<?,?>> |
gaugeMapSize(java.lang.String name,
java.lang.Iterable<Tag> tags,
T map)
Register a gauge that reports the size of the
Map . |
RequiredSearch |
get(java.lang.String name)
Initiate a search beginning with a metric name.
|
protected abstract java.util.concurrent.TimeUnit |
getBaseTimeUnit() |
protected java.lang.String |
getConventionName(Meter.Id id) |
protected java.util.List<Tag> |
getConventionTags(Meter.Id id) |
java.util.List<Meter> |
getMeters() |
boolean |
isClosed()
If the registry is closed, it will no longer accept new meters and any publishing activity will cease.
|
protected void |
meterRegistrationFailed(Meter.Id id,
java.lang.String reason)
Handle a meter registration failure.
|
MeterRegistry.More |
more()
Access to less frequently used meter types and patterns.
|
protected abstract Counter |
newCounter(Meter.Id id)
Build a new counter to be added to the registry.
|
protected abstract DistributionSummary |
newDistributionSummary(Meter.Id id,
DistributionStatisticConfig distributionStatisticConfig,
double scale)
Build a new distribution summary to be added to the registry.
|
protected abstract <T> FunctionCounter |
newFunctionCounter(Meter.Id id,
T obj,
java.util.function.ToDoubleFunction<T> countFunction)
Build a new function counter to be added to the registry.
|
protected abstract <T> FunctionTimer |
newFunctionTimer(Meter.Id id,
T obj,
java.util.function.ToLongFunction<T> countFunction,
java.util.function.ToDoubleFunction<T> totalTimeFunction,
java.util.concurrent.TimeUnit totalTimeFunctionUnit)
Build a new function timer to be added to the registry.
|
protected abstract <T> Gauge |
newGauge(Meter.Id id,
T obj,
java.util.function.ToDoubleFunction<T> valueFunction)
Build a new gauge to be added to the registry.
|
protected LongTaskTimer |
newLongTaskTimer(Meter.Id id)
Deprecated.
Implement
newLongTaskTimer(Meter.Id, DistributionStatisticConfig) instead. |
protected LongTaskTimer |
newLongTaskTimer(Meter.Id id,
DistributionStatisticConfig distributionStatisticConfig)
Build a new long task timer to be added to the registry.
|
protected abstract Meter |
newMeter(Meter.Id id,
Meter.Type type,
java.lang.Iterable<Measurement> measurements)
Build a new custom meter to be added to the registry.
|
protected <T> TimeGauge |
newTimeGauge(Meter.Id id,
T obj,
java.util.concurrent.TimeUnit valueFunctionUnit,
java.util.function.ToDoubleFunction<T> valueFunction)
Build a new time gauge to be added to the registry.
|
protected abstract Timer |
newTimer(Meter.Id id,
DistributionStatisticConfig distributionStatisticConfig,
PauseDetector pauseDetector)
Build a new timer to be added to the registry.
|
Meter |
remove(Meter.Id mappedId)
|
Meter |
remove(Meter meter)
|
Meter |
removeByPreFilterId(Meter.Id preFilterId)
Remove a
Meter from this registry based on its Meter.Id
before applying this registry's MeterFilter s to the given Meter.Id . |
DistributionSummary |
summary(java.lang.String name,
java.lang.Iterable<Tag> tags)
Measures the distribution of samples.
|
DistributionSummary |
summary(java.lang.String name,
java.lang.String... tags)
Measures the distribution of samples.
|
Timer |
timer(java.lang.String name,
java.lang.Iterable<Tag> tags)
Measures the time taken for short tasks and the count of these tasks.
|
Timer |
timer(java.lang.String name,
java.lang.String... tags)
Measures the time taken for short tasks and the count of these tasks.
|
protected final Clock clock
protected MeterRegistry(Clock clock)
protected abstract <T> Gauge newGauge(Meter.Id id, @Nullable T obj, java.util.function.ToDoubleFunction<T> valueFunction)
T
- The type of the state object from which the gauge value is extracted.id
- The id that uniquely identifies the gauge.obj
- State object used to compute a value.valueFunction
- Function that is applied on the value for the number.protected abstract Counter newCounter(Meter.Id id)
id
- The id that uniquely identifies the counter.@Deprecated protected LongTaskTimer newLongTaskTimer(Meter.Id id)
newLongTaskTimer(Meter.Id, DistributionStatisticConfig)
instead.id
- The id that uniquely identifies the long task timer.protected LongTaskTimer newLongTaskTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig)
id
- The id that uniquely identifies the long task timer.distributionStatisticConfig
- Configuration for published distribution statistics.protected abstract Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector)
id
- The id that uniquely identifies the timer.distributionStatisticConfig
- Configuration for published distribution statistics.pauseDetector
- The pause detector to use for coordinated omission compensation.protected abstract DistributionSummary newDistributionSummary(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale)
id
- The id that uniquely identifies the distribution summary.distributionStatisticConfig
- Configuration for published distribution statistics.scale
- Multiply every recorded sample by this factor.protected abstract Meter newMeter(Meter.Id id, Meter.Type type, java.lang.Iterable<Measurement> measurements)
id
- The id that uniquely identifies the custom meter.type
- What kind of meter this is.measurements
- A set of measurements describing how to sample this meter.protected <T> TimeGauge newTimeGauge(Meter.Id id, @Nullable T obj, java.util.concurrent.TimeUnit valueFunctionUnit, java.util.function.ToDoubleFunction<T> valueFunction)
T
- The type of the object upon which the value function derives a measurement.id
- The id that uniquely identifies the time gauge.obj
- The state object from which the value function derives a measurement.valueFunctionUnit
- The base unit of time returned by the value function.valueFunction
- A function returning a time value that can go up or down.protected abstract <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, java.util.function.ToLongFunction<T> countFunction, java.util.function.ToDoubleFunction<T> totalTimeFunction, java.util.concurrent.TimeUnit totalTimeFunctionUnit)
T
- The type of the object upon which the value functions derives their measurements.id
- The id that uniquely identifies the function timer.obj
- The state object from which the count and total functions derive measurements.countFunction
- A monotonically increasing count function.totalTimeFunction
- A monotonically increasing total time function.totalTimeFunctionUnit
- The base unit of time of the totals returned by the total time function.protected abstract <T> FunctionCounter newFunctionCounter(Meter.Id id, T obj, java.util.function.ToDoubleFunction<T> countFunction)
T
- The type of the object upon which the value function derives a measurement.id
- The id that uniquely identifies the function counter.obj
- The state object from which the count function derives a measurement.countFunction
- A monotonically increasing count function.protected java.lang.String getConventionName(Meter.Id id)
protected abstract java.util.concurrent.TimeUnit getBaseTimeUnit()
protected abstract DistributionStatisticConfig defaultHistogramConfig()
DistributionStatisticConfig.builder() .expiry(defaultStep) .build() .merge(DistributionStatisticConfig.DEFAULT);
public java.util.List<Meter> getMeters()
public void forEachMeter(java.util.function.Consumer<? super Meter> consumer)
consumer
- Consumer of each meter during iteration.public MeterRegistry.Config config()
public Search find(java.lang.String name)
null
.name
- The meter name to locate.public RequiredSearch get(java.lang.String name)
MeterNotFoundException
is thrown.name
- The meter name to locate.public Counter counter(java.lang.String name, java.lang.Iterable<Tag> tags)
name
- The base metric nametags
- Sequence of dimensions for breaking down the name.public Counter counter(java.lang.String name, java.lang.String... tags)
name
- The base metric nametags
- MUST be an even number of arguments representing key/value pairs of tags.public DistributionSummary summary(java.lang.String name, java.lang.Iterable<Tag> tags)
name
- The base metric nametags
- Sequence of dimensions for breaking down the name.public DistributionSummary summary(java.lang.String name, java.lang.String... tags)
name
- The base metric nametags
- MUST be an even number of arguments representing key/value pairs of tags.public Timer timer(java.lang.String name, java.lang.Iterable<Tag> tags)
name
- The base metric nametags
- Sequence of dimensions for breaking down the name.public Timer timer(java.lang.String name, java.lang.String... tags)
name
- The base metric nametags
- MUST be an even number of arguments representing key/value pairs of tags.public MeterRegistry.More more()
@Nullable public <T> T gauge(java.lang.String name, java.lang.Iterable<Tag> tags, @Nullable T stateObject, java.util.function.ToDoubleFunction<T> valueFunction)
valueFunction
is applied. The registration will keep a weak reference to the object so it will
not prevent garbage collection. Applying valueFunction
on the object should be thread safe.T
- The type of the state object from which the gauge value is extracted.name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.stateObject
- State object used to compute a value.valueFunction
- Function that produces an instantaneous gauge value from the state object.@Nullable public <T extends java.lang.Number> T gauge(java.lang.String name, java.lang.Iterable<Tag> tags, T number)
Number
.T
- The type of the number from which the gauge value is extracted.name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.number
- Thread-safe implementation of Number
used to access the value.@Nullable public <T extends java.lang.Number> T gauge(java.lang.String name, T number)
Number
.T
- The type of the state object from which the gauge value is extracted.name
- Name of the gauge being registered.number
- Thread-safe implementation of Number
used to access the value.@Nullable public <T> T gauge(java.lang.String name, T stateObject, java.util.function.ToDoubleFunction<T> valueFunction)
T
- The type of the state object from which the gauge value is extracted.name
- Name of the gauge being registered.stateObject
- State object used to compute a value.valueFunction
- Function that produces an instantaneous gauge value from the state object.@Nullable public <T extends java.util.Collection<?>> T gaugeCollectionSize(java.lang.String name, java.lang.Iterable<Tag> tags, T collection)
Collection
. The registration
will keep a weak reference to the collection so it will not prevent garbage collection.
The collection implementation used should be thread safe. Note that calling
Collection.size()
can be expensive for some collection implementations
and should be considered before registering.T
- The type of the state object from which the gauge value is extracted.name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.collection
- Thread-safe implementation of Collection
used to access the value.@Nullable public <T extends java.util.Map<?,?>> T gaugeMapSize(java.lang.String name, java.lang.Iterable<Tag> tags, T map)
Map
. The registration
will keep a weak reference to the collection so it will not prevent garbage collection.
The collection implementation used should be thread safe. Note that calling
Map.size()
can be expensive for some collection implementations
and should be considered before registering.T
- The type of the state object from which the gauge value is extracted.name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.map
- Thread-safe implementation of Map
used to access the value.@Incubating(since="1.1.0") @Nullable public Meter remove(Meter meter)
Meter
from this registry
. This is expected to be a Meter
with
the same Meter.Id
returned when registering a meter - which will have MeterFilter
s applied to it.meter
- The meter to remove@Incubating(since="1.3.16") @Nullable public Meter removeByPreFilterId(Meter.Id preFilterId)
Meter
from this registry
based on its Meter.Id
before applying this registry's MeterFilter
s to the given Meter.Id
.preFilterId
- the id of the meter to remove@Incubating(since="1.1.0") @Nullable public Meter remove(Meter.Id mappedId)
Meter
from this registry
based the given Meter.Id
as-is. The registry's
MeterFilter
s will not be applied to it. You can use the Meter.Id
of the Meter
returned
when registering a meter, since that will have MeterFilter
s already applied to it.mappedId
- The id of the meter to remove@Incubating(since="1.2.0") public void clear()
public void close()
public boolean isClosed()
true
if this registry is closed.