public class Metrics
extends java.lang.Object
MeterRegistry
is not possible for an instrumented
type.Modifier and Type | Class and Description |
---|---|
static class |
Metrics.More
Additional, less commonly used meter types.
|
Modifier and Type | Field and Description |
---|---|
static CompositeMeterRegistry |
globalRegistry |
Constructor and Description |
---|
Metrics() |
Modifier and Type | Method and Description |
---|---|
static void |
addRegistry(MeterRegistry registry)
Add a registry to the global composite registry.
|
static Counter |
counter(java.lang.String name,
java.lang.Iterable<Tag> tags)
Tracks a monotonically increasing value.
|
static Counter |
counter(java.lang.String name,
java.lang.String... tags)
Tracks a monotonically increasing value.
|
static <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 . |
static <T> T |
gauge(java.lang.String name,
java.lang.Iterable<Tag> tags,
T obj,
java.util.function.ToDoubleFunction<T> valueFunction)
Register a gauge that reports the value of the object after the function
valueFunction is applied. |
static <T extends java.lang.Number> |
gauge(java.lang.String name,
T number)
Register a gauge that reports the value of the
Number . |
static <T> T |
gauge(java.lang.String name,
T obj,
java.util.function.ToDoubleFunction<T> valueFunction)
Register a gauge that reports the value of the object.
|
static <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 . |
static <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 . |
static Metrics.More |
more()
Access to less frequently used meter types and patterns.
|
static void |
removeRegistry(MeterRegistry registry)
Remove a registry from the global composite registry.
|
static DistributionSummary |
summary(java.lang.String name,
java.lang.Iterable<Tag> tags)
Measures the distribution of samples.
|
static DistributionSummary |
summary(java.lang.String name,
java.lang.String... tags)
Measures the distribution of samples.
|
static Timer |
timer(java.lang.String name,
java.lang.Iterable<Tag> tags)
Measures the time taken for short tasks and the count of these tasks.
|
static Timer |
timer(java.lang.String name,
java.lang.String... tags)
Measures the time taken for short tasks and the count of these tasks.
|
public static final CompositeMeterRegistry globalRegistry
public static void addRegistry(MeterRegistry registry)
registry
- Registry to add.public static void removeRegistry(MeterRegistry registry)
registry
- Registry to remove.public static 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 static 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 static 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 static 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 static 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 static 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 static Metrics.More more()
@Nullable public static <T> T gauge(java.lang.String name, java.lang.Iterable<Tag> tags, T obj, 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.
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.
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.obj
- Object used to compute a value.valueFunction
- Function that is applied on the value for the number.@Nullable public static <T extends java.lang.Number> T gauge(java.lang.String name, java.lang.Iterable<Tag> tags, T number)
Number
.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.number
- Thread-safe implementation of Number
used to access the value.@Nullable public static <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 static <T> T gauge(java.lang.String name, T obj, java.util.function.ToDoubleFunction<T> valueFunction)
T
- The type of the state object from which the gauge value is extracted.Fname
- Name of the gauge being registered.obj
- Object used to compute a value.valueFunction
- Function that is applied on the value for the number.@Nullable public static <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 static <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.