Class MetricRegistry

java.lang.Object
org.eclipse.microprofile.metrics.MetricRegistry

public abstract class MetricRegistry extends Object
The registry that stores metrics and their metadata. The MetricRegistry provides methods to register, create and retrieve metrics and their respective metadata.
See Also:
  • Constructor Details

    • MetricRegistry

      public MetricRegistry()
  • Method Details

    • name

      public static String name(String name, String... names)
      Concatenates elements to form a dotted name, eliding any null values or empty strings.
      Parameters:
      name - the first element of the name
      names - the remaining elements of the name
      Returns:
      name and names concatenated by periods
    • name

      public static String name(Class<?> klass, String... names)
      Concatenates a class name and elements to form a dotted name, eliding any null values or empty strings.
      Parameters:
      klass - the first element of the name
      names - the remaining elements of the name
      Returns:
      klass and names concatenated by periods
    • register

      public abstract <T extends Metric> T register(String name, T metric) throws IllegalArgumentException
      Given a Metric, registers it under the given name. A Metadata object will be registered with the name and type.
      Type Parameters:
      T - the type of the metric
      Parameters:
      name - the name of the metric
      metric - the metric
      Returns:
      metric
      Throws:
      IllegalArgumentException - if the name is already registered
    • register

      public abstract <T extends Metric> T register(String name, T metric, Metadata metadata) throws IllegalArgumentException
      Given a Metric, registers it under the given name along with the provided Metadata.
      Type Parameters:
      T - the type of the metric
      Parameters:
      name - the name of the metric
      metric - the metric
      metadata - the metadata
      Returns:
      metric
      Throws:
      IllegalArgumentException - if the name is already registered
    • counter

      public abstract Counter counter(String name)
      Return the Counter registered under this name; or create and register a new Counter if none is registered. If a Counter was created, a Metadata object will be registered with the name and type.
      Parameters:
      name - the name of the metric
      Returns:
      a new or pre-existing Counter
    • counter

      public abstract Counter counter(Metadata metadata)
      Return the Counter registered under the Metadata's name; or create and register a new Counter if none is registered. If a Counter was created, the provided Metadata object will be registered.

      Note: The Metadata will not be updated if the metric is already registered.

      Parameters:
      metadata - the name of the metric
      Returns:
      a new or pre-existing Counter
    • histogram

      public abstract Histogram histogram(String name)
      Return the Histogram registered under this name; or create and register a new Histogram if none is registered. If a Histogram was created, a Metadata object will be registered with the name and type.
      Parameters:
      name - the name of the metric
      Returns:
      a new or pre-existing Histogram
    • histogram

      public abstract Histogram histogram(Metadata metadata)
      Return the Histogram registered under the Metadata's name; or create and register a new Histogram if none is registered. If a Histogram was created, the provided Metadata object will be registered.

      Note: The Metadata will not be updated if the metric is already registered.

      Parameters:
      metadata - the name of the metric
      Returns:
      a new or pre-existing Histogram
    • meter

      public abstract Meter meter(String name)
      Return the Meter registered under this name; or create and register a new Meter if none is registered. If a Meter was created, a Metadata object will be registered with the name and type.
      Parameters:
      name - the name of the metric
      Returns:
      a new or pre-existing Meter
    • meter

      public abstract Meter meter(Metadata metadata)
      Return the Meter registered under the Metadata's name; or create and register a new Meter if none is registered. If a Meter was created, the provided Metadata object will be registered.

      Note: The Metadata will not be updated if the metric is already registered.

      Parameters:
      metadata - the name of the metric
      Returns:
      a new or pre-existing Meter
    • timer

      public abstract Timer timer(String name)
      Return the Timer registered under this name; or create and register a new Timer if none is registered. If a Timer was created, a Metadata object will be registered with the name and type.
      Parameters:
      name - the name of the metric
      Returns:
      a new or pre-existing Timer
    • timer

      public abstract Timer timer(Metadata metadata)
      Return the Timer registered under the Metadata's name; or create and register a new Timer if none is registered. If a Timer was created, the provided Metadata object will be registered.

      Note: The Metadata will not be updated if the metric is already registered.

      Parameters:
      metadata - the name of the metric
      Returns:
      a new or pre-existing Timer
    • remove

      public abstract boolean remove(String name)
      Removes the metric with the given name.
      Parameters:
      name - the name of the metric
      Returns:
      whether or not the metric was removed
    • removeMatching

      public abstract void removeMatching(MetricFilter filter)
      Removes all metrics which match the given filter.
      Parameters:
      filter - a filter
    • getNames

      public abstract SortedSet<String> getNames()
      Returns a set of the names of all the metrics in the registry.
      Returns:
      the names of all the metrics
    • getGauges

      public abstract SortedMap<String,Gauge> getGauges()
      Returns a map of all the gauges in the registry and their names.
      Returns:
      all the gauges in the registry
    • getGauges

      public abstract SortedMap<String,Gauge> getGauges(MetricFilter filter)
      Returns a map of all the gauges in the registry and their names which match the given filter.
      Parameters:
      filter - the metric filter to match
      Returns:
      all the gauges in the registry
    • getCounters

      public abstract SortedMap<String,Counter> getCounters()
      Returns a map of all the counters in the registry and their names.
      Returns:
      all the counters in the registry
    • getCounters

      public abstract SortedMap<String,Counter> getCounters(MetricFilter filter)
      Returns a map of all the counters in the registry and their names which match the given filter.
      Parameters:
      filter - the metric filter to match
      Returns:
      all the counters in the registry
    • getHistograms

      public abstract SortedMap<String,Histogram> getHistograms()
      Returns a map of all the histograms in the registry and their names.
      Returns:
      all the histograms in the registry
    • getHistograms

      public abstract SortedMap<String,Histogram> getHistograms(MetricFilter filter)
      Returns a map of all the histograms in the registry and their names which match the given filter.
      Parameters:
      filter - the metric filter to match
      Returns:
      all the histograms in the registry
    • getMeters

      public abstract SortedMap<String,Meter> getMeters()
      Returns a map of all the meters in the registry and their names.
      Returns:
      all the meters in the registry
    • getMeters

      public abstract SortedMap<String,Meter> getMeters(MetricFilter filter)
      Returns a map of all the meters in the registry and their names which match the given filter.
      Parameters:
      filter - the metric filter to match
      Returns:
      all the meters in the registry
    • getTimers

      public abstract SortedMap<String,Timer> getTimers()
      Returns a map of all the timers in the registry and their names.
      Returns:
      all the timers in the registry
    • getTimers

      public abstract SortedMap<String,Timer> getTimers(MetricFilter filter)
      Returns a map of all the timers in the registry and their names which match the given filter.
      Parameters:
      filter - the metric filter to match
      Returns:
      all the timers in the registry
    • getMetrics

      public abstract Map<String,Metric> getMetrics()
      Returns a map of all the metrics in the registry and their names.
      Returns:
      all the metrics in the registry
    • getMetadata

      public abstract Map<String,Metadata> getMetadata()
      Returns a map of all the metadata in the registry and their names.
      Returns:
      all the metadata in the registry