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 of MeterRegistry 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

    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>
    T
    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>
    T
    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<?>>
    T
    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<?,​ ?>>
    T
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Metrics

      public Metrics()
  • Method Details

    • 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 name
      tags - 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 name
      tags - 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 name
      tags - 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 name
      tags - 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 name
      tags - 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 name
      tags - 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 function 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.

      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 the Number.
      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 of Number 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 the Number.
      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 of Number 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 the 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.
      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 of Collection 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 the 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.
      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 of Map used to access the value.
      Returns:
      The number that was passed in so the registration can be done as part of an assignment statement.