Interface MeterRegistry
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceMeterRegistry.Builder<B extends MeterRegistry.Builder<B,R>, R extends MeterRegistry> Builder for creating a new meter registry. -
Method Summary
Modifier and TypeMethodDescriptionclock()Returns the defaultClockin use by the registry.voidclose()Closes this meter registry and the resources it owns, including publisher registries.Locates a previously-registered counter.static MeterRegistrycreate()Deprecated, for removal: This API element is subject to removal in a future version.static MeterRegistrycreate(MetricsConfig metricsConfig) Deprecated, for removal: This API element is subject to removal in a future version.either useServiceRegistry.get(Class)to get the global meter registry, or get theMetricsFactory.createMeterRegistry(MetricsConfig)to get a custom instanceLocates a previously-registered gauge.<B extends Meter.Builder<B,M>, M extends Meter>
MgetOrCreate(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.booleanIndicates if the meter has been deleted.default booleanisMeterEnabled(String name, Map<String, String> tags) Returns whether the specified meter is enabled.default booleanDeprecated, for removal: This API element is subject to removal in a future version.Locates a previously-registered meter of the specified type, matching the name and tags.meters()Returns all previously-registered meters.Deprecated, for removal: This API element is subject to removal in a future version.Usemeters().Returns previously-registered meters which match the specifiedPredicate.default MetricsFactoryMetrics factory that created this registry.onMeterAdded(Consumer<Meter> onAddListener) Enroll a listener to be notified when aMeteris added.onMeterRemoved(Consumer<Meter> onRemoveListener) Enroll a listener to be notified when aMeteris removed.Removes a previously-registered meter.Removes a previously-registered meter with the specified ID.Deprecated, for removal: This API element is subject to removal in a future version.Useremove(Meter.Id).Removes a previously-registered meter with the specified name and tags.Deprecated, for removal: This API element is subject to removal in a future version.scopes()Deprecated, for removal: This API element is subject to removal in a future version.Always returns an empty iterable and will be removed.default Optional<DistributionSummary> Locates a previously-registered distribution summary.Locates a previously-registered timer.
-
Method Details
-
create
Deprecated, for removal: This API element is subject to removal in a future version.either useServiceRegistry.get(Class)to get the global meter registry, or get theMetricsFactory.createMeterRegistry(MetricsConfig)to get a custom instanceCreates a new meter registry. For general case where you just need aMeterRegistry, useServices.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 useServiceRegistry.get(Class)to get the global meter registry, or get theMetricsFactory.createMeterRegistry(MetricsConfig)to get a custom instanceCreates a meter registry, not saved as the global registry, based on the provided metrics config.- Parameters:
metricsConfig- metrics config- Returns:
- new meter registry
-
meters
-
meters
-
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.Usemeters(). Scope selection is ignored and this method will be removed.Returns all previously-registered meters, ignoring the scope selection.- Parameters:
scopeSelection- ignored; must not benull- Returns:
- all registered meters
-
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 usingMetricsFactory. TheServiceRegistrycloses its shared registry; application code must not close that registry. -
isMeterEnabled
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 checktags- 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.UseisMeterEnabled(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 checktags- tags of the meter to checkscope- ignored; must not benull- Returns:
- true if the meter is enabled; false otherwise
-
clock
-
getOrCreate
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 meterM- 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
-
summary
-
gauge
-
timer
-
meter
Locates a previously-registered meter of the specified type, matching the name and tags.The method throws an
ClassCastExceptionif 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 findname- name to matchtags- tags to match- Returns:
Optionalof the previously-regsitered meter; empty if not found
-
remove
-
remove
-
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.Useremove(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 removescope- ignored; must not benull- Returns:
- the removed meter; empty if the specified ID does not correspond to a registered meter
-
remove
Removes a previously-registered meter with the specified name and tags.- Parameters:
name- meter nametags- 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.Useremove(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 nametags- tags for further identifying the meterscope- ignored; must not benull- Returns:
- the removed meter; empty if the specified name and tags do not correspond to a registered meter
-
isDeleted
-
onMeterAdded
Enroll a listener to be notified when aMeteris added.- Parameters:
onAddListener- listener to invoke upon each meter registration- Returns:
- the meter registry
-
onMeterRemoved
Enroll a listener to be notified when aMeteris removed.- Parameters:
onRemoveListener- listener to invoke upon each meter removal- Returns:
- the meter registry
-
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
-
ServiceRegistry.get(Class)to get the global meter registry, or get theMetricsFactory.createMeterRegistry(MetricsConfig)to get a custom instance