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.
Modifier and Type | Class and Description |
---|---|
class |
MeterRegistry.Config
Access to configuration options for this registry.
|
class |
MeterRegistry.More |
class |
MeterRegistry.Search |
Modifier | Constructor and Description |
---|---|
protected |
MeterRegistry(Clock clock) |
Modifier and Type | Method and Description |
---|---|
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 HistogramConfig |
defaultHistogramConfig()
Every custom registry implementation should define a default histogram expiry:
|
MeterRegistry.Search |
find(java.lang.String name) |
void |
forEachMeter(java.util.function.Consumer<? super Meter> consumer) |
<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 obj,
java.util.function.ToDoubleFunction<T> f)
Register a gauge that reports the value of the object after the function
f 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 obj,
java.util.function.ToDoubleFunction<T> f)
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 . |
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() |
MeterRegistry.More |
more()
Access to less frequently used meter types and patterns.
|
protected abstract Counter |
newCounter(Meter.Id id) |
protected abstract DistributionSummary |
newDistributionSummary(Meter.Id id,
HistogramConfig histogramConfig) |
protected abstract <T> FunctionCounter |
newFunctionCounter(Meter.Id id,
T obj,
java.util.function.ToDoubleFunction<T> f) |
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 totalTimeFunctionUnits) |
protected abstract <T> Gauge |
newGauge(Meter.Id id,
T obj,
java.util.function.ToDoubleFunction<T> f) |
protected abstract LongTaskTimer |
newLongTaskTimer(Meter.Id id) |
protected abstract Meter |
newMeter(Meter.Id id,
Meter.Type type,
java.lang.Iterable<Measurement> measurements) |
protected <T> TimeGauge |
newTimeGauge(Meter.Id id,
T obj,
java.util.concurrent.TimeUnit fUnit,
java.util.function.ToDoubleFunction<T> f) |
protected abstract Timer |
newTimer(Meter.Id id,
HistogramConfig histogramConfig,
PauseDetector pauseDetector) |
DistributionSummary |
summary(java.lang.String name,
java.lang.Iterable<Tag> tags)
Measures the sample distribution of events.
|
DistributionSummary |
summary(java.lang.String name,
java.lang.String... tags)
Measures the sample distribution of events.
|
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, T obj, java.util.function.ToDoubleFunction<T> f)
protected abstract LongTaskTimer newLongTaskTimer(Meter.Id id)
protected abstract Timer newTimer(Meter.Id id, HistogramConfig histogramConfig, PauseDetector pauseDetector)
protected abstract DistributionSummary newDistributionSummary(Meter.Id id, HistogramConfig histogramConfig)
protected abstract Meter newMeter(Meter.Id id, Meter.Type type, java.lang.Iterable<Measurement> measurements)
protected <T> TimeGauge newTimeGauge(Meter.Id id, T obj, java.util.concurrent.TimeUnit fUnit, java.util.function.ToDoubleFunction<T> f)
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 totalTimeFunctionUnits)
protected abstract <T> FunctionCounter newFunctionCounter(Meter.Id id, T obj, java.util.function.ToDoubleFunction<T> f)
protected java.lang.String getConventionName(Meter.Id id)
protected abstract java.util.concurrent.TimeUnit getBaseTimeUnit()
protected abstract HistogramConfig defaultHistogramConfig()
histogramConfig.builder() .histogramExpiry(defaultStep) .build() .merge(HistogramConfig.DEFAULT);
public java.util.List<Meter> getMeters()
public void forEachMeter(java.util.function.Consumer<? super Meter> consumer)
public MeterRegistry.Config config()
public MeterRegistry.Search find(java.lang.String name)
public Counter counter(java.lang.String name, java.lang.Iterable<Tag> tags)
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)
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)
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()
public <T> T gauge(java.lang.String name, java.lang.Iterable<Tag> tags, T obj, java.util.function.ToDoubleFunction<T> f)
f
is applied. The registration will keep a weak reference to the object so it will
not prevent garbage collection. Applying f
on the object should be thread safe.
If multiple gauges are registered with the same id, then the values will be aggregated and the sum will be reported. For example, registering multiple gauges for active threads in a thread pool with the same id would produce a value that is the overall number of active threads. For other behaviors, manage it on the user side and avoid multiple registrations.
name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.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 gauge(java.lang.String name, java.lang.Iterable<Tag> tags, T number)
Number
.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.public <T extends java.lang.Number> T gauge(java.lang.String name, T number)
Number
.name
- Name of the gauge being registered.number
- Thread-safe implementation of Number
used to access the value.public <T> T gauge(java.lang.String name, T obj, java.util.function.ToDoubleFunction<T> f)
name
- Name of the gauge being registered.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 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.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.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.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.