Package io.micrometer.core.instrument
Class Metrics
java.lang.Object
io.micrometer.core.instrument.Metrics
Generator of meters bound to a static global composite registry. For use especially in
places where dependency injection of
MeterRegistry
is not possible for an
instrumented type.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Additional, less commonly used meter types. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addRegistry
(MeterRegistry registry) Add a registry to the global composite registry.static Counter
Tracks a monotonically increasing value.static Counter
Tracks a monotonically increasing value.static <T extends Number>
TRegister a gauge that reports the value of theNumber
.static <T> T
gauge
(String name, Iterable<Tag> tags, T obj, ToDoubleFunction<T> valueFunction) Register a gauge that reports the value of the object after the functionvalueFunction
is applied.static <T extends Number>
TRegister a gauge that reports the value of theNumber
.static <T> T
gauge
(String name, T obj, ToDoubleFunction<T> valueFunction) Register a gauge that reports the value of the object.static <T extends Collection<?>>
TgaugeCollectionSize
(String name, Iterable<Tag> tags, T collection) Register a gauge that reports the size of theCollection
.static <T extends Map<?,
?>>
TgaugeMapSize
(String name, Iterable<Tag> tags, T map) Register a gauge that reports the size of theMap
.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
Measures the distribution of samples.static DistributionSummary
Measures the distribution of samples.static Timer
Measures the time taken for short tasks and the count of these tasks.static Timer
Measures the time taken for short tasks and the count of these tasks.
-
Field Details
-
globalRegistry
-
-
Constructor Details
-
Metrics
public Metrics()
-
-
Method Details
-
addRegistry
Add a registry to the global composite registry.- Parameters:
registry
- Registry to add.
-
removeRegistry
Remove a registry from the global composite registry. Removing a registry does not remove any meters that were added to it by previous participation in the global composite.- Parameters:
registry
- Registry to remove.
-
counter
Tracks a monotonically increasing value.- Parameters:
name
- The base metric nametags
- Sequence of dimensions for breaking down the name.- Returns:
- A new or existing counter.
-
counter
Tracks a monotonically increasing value.- Parameters:
name
- The base metric nametags
- MUST be an even number of arguments representing key/value pairs of tags.- Returns:
- A new or existing counter.
-
summary
Measures the distribution of samples.- Parameters:
name
- The base metric nametags
- Sequence of dimensions for breaking down the name.- Returns:
- A new or existing distribution summary.
-
summary
Measures the distribution of samples.- Parameters:
name
- The base metric nametags
- MUST be an even number of arguments representing key/value pairs of tags.- Returns:
- A new or existing distribution summary.
-
timer
Measures the time taken for short tasks and the count of these tasks.- Parameters:
name
- The base metric nametags
- Sequence of dimensions for breaking down the name.- Returns:
- A new or existing timer.
-
timer
Measures the time taken for short tasks and the count of these tasks.- Parameters:
name
- The base metric nametags
- MUST be an even number of arguments representing key/value pairs of tags.- Returns:
- A new or existing timer.
-
more
Access to less frequently used meter types and patterns.- Returns:
- Access to additional meter types and patterns.
-
gauge
@Nullable public static <T> T gauge(String name, Iterable<Tag> tags, T obj, ToDoubleFunction<T> valueFunction) Register a gauge that reports the value of the object after the functionvalueFunction
is applied. The registration will keep a weak reference to the object so it will not prevent garbage collection. ApplyingvalueFunction
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.
- Type Parameters:
T
- The type of the state object from which the gauge value is extracted.- Parameters:
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.- Returns:
- The number that was passed in so the registration can be done as part of an assignment statement.
-
gauge
Register a gauge that reports the value of theNumber
.- Type Parameters:
T
- The type of the state object from which the gauge value is extracted.- Parameters:
name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.number
- Thread-safe implementation ofNumber
used to access the value.- Returns:
- The number that was passed in so the registration can be done as part of an assignment statement.
-
gauge
Register a gauge that reports the value of theNumber
.- Type Parameters:
T
- The type of the state object from which the gauge value is extracted.- Parameters:
name
- Name of the gauge being registered.number
- Thread-safe implementation ofNumber
used to access the value.- Returns:
- The number that was passed in so the registration can be done as part of an assignment statement.
-
gauge
Register a gauge that reports the value of the object.- Type Parameters:
T
- The type of the state object from which the gauge value is extracted.F- Parameters:
name
- Name of the gauge being registered.obj
- Object used to compute a value.valueFunction
- Function that is applied on the value for the number.- Returns:
- The number that was passed in so the registration can be done as part of an assignment statement.
-
gaugeCollectionSize
@Nullable public static <T extends Collection<?>> T gaugeCollectionSize(String name, Iterable<Tag> tags, T collection) Register a gauge that reports the size of theCollection
. 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 callingCollection.size()
can be expensive for some collection implementations and should be considered before registering.- Type Parameters:
T
- The type of the state object from which the gauge value is extracted.- Parameters:
name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.collection
- Thread-safe implementation ofCollection
used to access the value.- Returns:
- The number that was passed in so the registration can be done as part of an assignment statement.
-
gaugeMapSize
@Nullable public static <T extends Map<?,?>> T gaugeMapSize(String name, Iterable<Tag> tags, T map) Register a gauge that reports the size of theMap
. 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 callingMap.size()
can be expensive for some collection implementations and should be considered before registering.- Type Parameters:
T
- The type of the state object from which the gauge value is extracted.- Parameters:
name
- Name of the gauge being registered.tags
- Sequence of dimensions for breaking down the name.map
- Thread-safe implementation ofMap
used to access the value.- Returns:
- The number that was passed in so the registration can be done as part of an assignment statement.
-