Interface MeterRegistry

All Superinterfaces:
Wrapper, Wrapper

public interface MeterRegistry extends Wrapper
Manages the look-up and registration of meters.

The shared registry obtained from Services or an ServiceRegistry is owned and closed by that service registry; application code must not close it. A custom registry created using MetricsFactory is owned by the caller, which must close it to release the registry and any publisher resources it owns.

  • Method Details

    • create

      @Deprecated(forRemoval=true, since="27.0.0") static MeterRegistry create()
      Deprecated, for removal: This API element is subject to removal in a future version.
      either use ServiceRegistry.get(Class) to get the global meter registry, or get the MetricsFactory.createMeterRegistry(MetricsConfig) to get a custom instance
      Creates a new meter registry. For general case where you just need a MeterRegistry, use Services.get(MeterRegistry.class).
      Returns:
      new meter registry
    • create

      @Deprecated(forRemoval=true, since="27.0.0") static MeterRegistry create(MetricsConfig metricsConfig)
      Deprecated, for removal: This API element is subject to removal in a future version.
      either use ServiceRegistry.get(Class) to get the global meter registry, or get the MetricsFactory.createMeterRegistry(MetricsConfig) to get a custom instance
      Creates a meter registry, not saved as the global registry, based on the provided metrics config.
      Parameters:
      metricsConfig - metrics config
      Returns:
      new meter registry
    • meters

      List<Meter> meters()
      Returns all previously-registered meters.
      Returns:
      registered meters
    • meters

      Collection<Meter> meters(Predicate<Meter> filter)
      Returns previously-registered meters which match the specified Predicate.
      Parameters:
      filter - the predicate with which to evaluate each Meter
      Returns:
      meters which match the predicate
    • meters

      @Deprecated(forRemoval=true, since="27.0.0") default Iterable<Meter> meters(Iterable<String> scopeSelection)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use meters(). Scope selection is ignored and this method will be removed.
      Returns all previously-registered meters, ignoring the scope selection.
      Parameters:
      scopeSelection - ignored; must not be null
      Returns:
      all registered meters
    • scopes

      @Deprecated(forRemoval=true, since="27.0.0") default Iterable<String> scopes()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Always returns an empty iterable and will be removed.
      Always returns an empty iterable and will be removed.
      Returns:
      empty iterable
    • close

      void close()
      Closes this meter registry and the resources it owns, including publisher registries. Callers must close custom registries they create using MetricsFactory. The ServiceRegistry closes its shared registry; application code must not close that registry.
    • isMeterEnabled

      default boolean isMeterEnabled(String name, Map<String,String> tags)
      Returns whether the specified meter is enabled.

      The default implementation delegates to the deprecated overload for compatibility with existing implementations. Implementations should override this method to apply provider-neutral enablement rules. Legacy implementations which override the deprecated overload continue to work.

      Parameters:
      name - name of the meter to check
      tags - tags of the meter to check
      Returns:
      true if the meter is enabled; false otherwise
    • isMeterEnabled

      @Deprecated(forRemoval=true, since="27.0.0") default boolean isMeterEnabled(String name, Map<String,String> tags, Optional<String> scope)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use isMeterEnabled(String, Map). Scope is ignored and this method will be removed.
      Returns whether the specified meter is enabled, ignoring the scope.

      The default implementation delegates to isMeterEnabled(String, Map). Implementations must override either this method or the scope-free overload.

      Parameters:
      name - name of the meter to check
      tags - tags of the meter to check
      scope - ignored; must not be null
      Returns:
      true if the meter is enabled; false otherwise
    • clock

      Clock clock()
      Returns the default Clock in use by the registry.
      Returns:
      default clock
    • getOrCreate

      <B extends Meter.Builder<B,M>, M extends Meter> M getOrCreate(B builder)
      Locates a previously-registered meter using the name and tags in the provided builder or, if not found, registers a new one using the provided builder.
      Type Parameters:
      B - builder for the meter
      M - type of the meter
      Parameters:
      builder - builder to use in finding or creating a meter
      Returns:
      the previously-registered meter with the same name and tags or, if none, the newly-registered one
    • counter

      default Optional<Counter> counter(String name, Iterable<Tag> tags)
      Locates a previously-registered counter.
      Parameters:
      name - name to match
      tags - tags to match
      Returns:
      Optional of the previously-registered counter; empty if not found
    • summary

      default Optional<DistributionSummary> summary(String name, Iterable<Tag> tags)
      Locates a previously-registered distribution summary.
      Parameters:
      name - name to match
      tags - tags to match
      Returns:
      Optional of the previously-registered distribution summary; empty if not found
    • gauge

      default Optional<Gauge> gauge(String name, Iterable<Tag> tags)
      Locates a previously-registered gauge.
      Parameters:
      name - name to match
      tags - tags to match
      Returns:
      Optional of the previously-registered gauge; empty if not found
    • timer

      default Optional<Timer> timer(String name, Iterable<Tag> tags)
      Locates a previously-registered timer.
      Parameters:
      name - name to match
      tags - tags to match
      Returns:
      Optional of the previously-registered timer; empty if not found
    • meter

      <M extends Meter> Optional<M> meter(Class<M> mClass, String name, Iterable<Tag> tags)
      Locates a previously-registered meter of the specified type, matching the name and tags.

      The method throws an ClassCastException if a meter exists with the name and tags but is not type-compatible with the provided class.

      Type Parameters:
      M - type of the meter to find
      Parameters:
      mClass - type of the meter to find
      name - name to match
      tags - tags to match
      Returns:
      Optional of the previously-regsitered meter; empty if not found
    • remove

      Optional<Meter> remove(Meter meter)
      Removes a previously-registered meter.
      Parameters:
      meter - the meter to remove
      Returns:
      the removed meter; empty if the meter is not currently registered
    • remove

      Optional<Meter> remove(Meter.Id id)
      Removes a previously-registered meter with the specified ID.
      Parameters:
      id - ID for the meter to remove
      Returns:
      the removed meter; empty if the meter is not currently registered
    • remove

      @Deprecated(forRemoval=true, since="27.0.0") default Optional<Meter> remove(Meter.Id id, String scope)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use remove(Meter.Id). Scope is ignored and this method will be removed.
      Removes a previously-registered meter with the specified ID, ignoring the scope.
      Parameters:
      id - ID for the meter to remove
      scope - ignored; must not be null
      Returns:
      the removed meter; empty if the specified ID does not correspond to a registered meter
    • remove

      Optional<Meter> remove(String name, Iterable<Tag> tags)
      Removes a previously-registered meter with the specified name and tags.
      Parameters:
      name - meter name
      tags - tags for further identifying the meter
      Returns:
      the removed meter; empty if the specified name and tags do not correspond to a registered meter
    • remove

      @Deprecated(forRemoval=true, since="27.0.0") default Optional<Meter> remove(String name, Iterable<Tag> tags, String scope)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use remove(String, Iterable). Scope is ignored and this method will be removed.
      Removes a previously-registered meter with the specified name and tags, ignoring the scope.
      Parameters:
      name - meter name
      tags - tags for further identifying the meter
      scope - ignored; must not be null
      Returns:
      the removed meter; empty if the specified name and tags do not correspond to a registered meter
    • isDeleted

      boolean isDeleted(Meter meter)
      Indicates if the meter has been deleted.
      Parameters:
      meter - Meter to check
      Returns:
      true if the meter has been deleted; false if it is still active
    • onMeterAdded

      MeterRegistry onMeterAdded(Consumer<Meter> onAddListener)
      Enroll a listener to be notified when a Meter is added.
      Parameters:
      onAddListener - listener to invoke upon each meter registration
      Returns:
      the meter registry
    • onMeterRemoved

      MeterRegistry onMeterRemoved(Consumer<Meter> onRemoveListener)
      Enroll a listener to be notified when a Meter is removed.
      Parameters:
      onRemoveListener - listener to invoke upon each meter removal
      Returns:
      the meter registry
    • metricsFactory

      default MetricsFactory metricsFactory()
      Metrics factory that created this registry.

      The default implementation returns the shared metrics factory from the service registry for compatibility. Implementations created by a different factory must override this method and return that factory.

      Returns:
      metrics factory