Class Metrics

java.lang.Object
io.micrometer.core.instrument.Metrics

public class Metrics extends 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.
  • 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(String name, 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(String name, 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(String name, 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(String name, 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(String name, 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(String name, 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(String name, Iterable<Tag> tags, T obj, 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 Number> T gauge(String name, 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 Number> T gauge(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(String name, T obj, 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 Collection<?>> T gaugeCollectionSize(String name, 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 Map<?, ?>> T gaugeMapSize(String name, 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.