Package io.micrometer.core.instrument
Class Metrics
- java.lang.Object
-
- io.micrometer.core.instrument.Metrics
-
public class Metrics extends java.lang.Object
Generator of meters bound to a static global composite registry. For use especially in places where dependency injection ofMeterRegistry
is not possible for an instrumented type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Metrics.More
Additional, less commonly used meter types.
-
Field Summary
Fields Modifier and Type Field Description static CompositeMeterRegistry
globalRegistry
-
Constructor Summary
Constructors Constructor Description Metrics()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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>
Tgauge(java.lang.String name, java.lang.Iterable<Tag> tags, T number)
Register a gauge that reports the value of theNumber
.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 functionvalueFunction
is applied.static <T extends java.lang.Number>
Tgauge(java.lang.String name, T number)
Register a gauge that reports the value of theNumber
.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<?>>
TgaugeCollectionSize(java.lang.String name, java.lang.Iterable<Tag> tags, T collection)
Register a gauge that reports the size of theCollection
.static <T extends java.util.Map<?,?>>
TgaugeMapSize(java.lang.String name, java.lang.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
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.
-
-
-
Field Detail
-
globalRegistry
public static final CompositeMeterRegistry globalRegistry
-
-
Method Detail
-
addRegistry
public static void addRegistry(MeterRegistry registry)
Add a registry to the global composite registry.- Parameters:
registry
- Registry to add.
-
removeRegistry
public static void removeRegistry(MeterRegistry registry)
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
public static Counter counter(java.lang.String name, java.lang.Iterable<Tag> tags)
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
public static Counter counter(java.lang.String name, java.lang.String... tags)
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
public static DistributionSummary summary(java.lang.String name, java.lang.Iterable<Tag> tags)
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
public static DistributionSummary summary(java.lang.String name, java.lang.String... tags)
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
public 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.- Parameters:
name
- The base metric nametags
- Sequence of dimensions for breaking down the name.- Returns:
- A new or existing timer.
-
timer
public static Timer timer(java.lang.String name, java.lang.String... tags)
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
public static Metrics.More 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(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 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
@Nullable public static <T extends java.lang.Number> T gauge(java.lang.String name, java.lang.Iterable<Tag> tags, T number)
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
@Nullable public static <T extends java.lang.Number> T gauge(java.lang.String name, T number)
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
@Nullable public 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.- 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 java.util.Collection<?>> T gaugeCollectionSize(java.lang.String name, java.lang.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 java.util.Map<?,?>> T gaugeMapSize(java.lang.String name, java.lang.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.
-
-