Interface MetricsFactory
public interface MetricsFactory
The basic contract for implementations of the Helidon metrics API, mostly acting as a factory for
meter builders rather than for meters themselves.
Applications normally inject MeterRegistry or use
Services.get(MeterRegistry.class) to obtain the shared
meter registry for registering and looking up meters. To create meter builders, timer samples, tags, snapshots, or custom
registries, applications inject MetricsFactory or use
Services.get(MetricsFactory.class).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. -
Method Summary
Modifier and TypeMethodDescriptionReturns the systemClockfrom the underlying metrics implementation.voidclose()Closes this metrics factory.static voidcloseAll()Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal.counterBuilder(String name) Creates a builder for aCounter.createMeterRegistry(Clock clock, MetricsConfig metricsConfig) createMeterRegistry(Clock clock, MetricsConfig metricsConfig, Consumer<Meter> onAddListener, Consumer<Meter> onRemoveListener) Creates a new caller-ownedMeterRegistryusing the providedClockandMetricsConfigand enrolling the specified listeners with the new meter registry.createMeterRegistry(MetricsConfig metricsConfig) Creates a new caller-ownedMeterRegistryusing the provided metrics config.createMeterRegistry(MetricsConfig metricsConfig, Consumer<Meter> onAddListener, Consumer<Meter> onRemoveListener) Creates a new caller-ownedMeterRegistryusing the provided metrics config and enrolling the specified listeners with the returned meter registry.Creates a builder for aDistributionStatisticsConfig.distributionSummaryBuilder(String name, DistributionStatisticsConfig.Builder configBuilder) Creates a builder for aDistributionSummary.<T> FunctionalCounter.Builder<T> functionalCounterBuilder(String name, T stateObject, Function<T, Long> fn) Creates a builder for a functionalCounter, essentially a counter-style wrapper around an external object.<N extends Number>
Gauge.Builder<N> gaugeBuilder(String name, Supplier<N> supplier) <T> Gauge.Builder<Double> gaugeBuilder(String name, T stateObject, ToDoubleFunction<T> fn) Creates a builder for a state-basedGauge.static MetricsFactoryDeprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal.static MetricsFactorygetInstance(Config ignoredConfig) Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal.Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal.default MeterRegistryglobalRegistry(MetricsConfig ignoredMetricsConfig) Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal.default MeterRegistryglobalRegistry(Consumer<Meter> ignoredOnAddListener, Consumer<Meter> ignoredOnRemoveListener, boolean ignoredBackfill) Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal.histogramSnapshotEmpty(long count, double total, double max) Returns an empty histogram snapshot with the specified aggregate values.<B extends MeterRegistry.Builder<B,M>, M extends MeterRegistry>
BReturns a builder for creating a new caller-ownedMeterRegistry.Returns theMetricsConfiginstance used to initialize the metrics factory.default MeternoOpMeter(Meter.Builder<?, ?> builder) Returns a no-opMeterof the type implied by the builder's runtime type, initialized with the builder's name and other required parameters.Creates aTagfrom the specified key and value.timerBuilder(String name) Creates a builder for aTimer.Returns aTimer.Samplefor measuring a duration using the system defaultClock.timerStart(Clock clock) Returns aTimer.Samplefor measuring a duration using the specifiedClock.timerStart(MeterRegistry registry) Returns aTimer.Samplefor measuring a duration, using the clock associated with the specifiedMeterRegistry.
-
Field Details
-
PULL_PUBLISHERS_PRESENT
Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. This constant is no longer used because publisher availability is specific to each meter registry.Qualifier for context setting indicating if any pull publishers are present.- See Also:
-
-
Method Details
-
getInstance
Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. UseServices.get(MetricsFactory.class)for the shared metrics factory, or create non-global metrics objects using the programmatic API.Returns the shared metrics factory fromServices.get(MetricsFactory.class).- Returns:
- shared metrics factory
-
getInstance
@Deprecated(since="27.0.0", forRemoval=true) static MetricsFactory getInstance(Config ignoredConfig) Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. Static config-based access is no longer supported. UseServices.get(MetricsFactory.class)for the shared metrics factory, or create non-global metrics objects using the programmatic API.Returns the shared metrics factory fromServices.get(MetricsFactory.class).- Parameters:
ignoredConfig- ignored config; must not benull- Returns:
- shared metrics factory
-
closeAll
Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. Metrics instances obtained from the service registry are closed by the service registry lifecycle.No-op.Metrics instances obtained from the service registry are closed by the service registry lifecycle.
-
close
void close()Closes this metrics factory.Applications do not normally need to invoke this method.
-
globalRegistry
Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. Obtain the shared registry fromServices.get(MeterRegistry.class). This method remains for metrics implementation compatibility.Returns the globalMeterRegistryfor this metrics factory.- Returns:
- the global meter registry
-
globalRegistry
@Deprecated(since="27.0.0", forRemoval=true) default MeterRegistry globalRegistry(MetricsConfig ignoredMetricsConfig) Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. Obtain the shared registry fromServices.get(MeterRegistry.class). To create a non-global registry with custom configuration, usecreateMeterRegistry(MetricsConfig).Returns this factory's global registry. The configuration is ignored and does not alter the global registry.- Parameters:
ignoredMetricsConfig- ignored configuration; must not benull- Returns:
- this factory's global meter registry
-
globalRegistry
@Deprecated(since="27.0.0", forRemoval=true) default MeterRegistry globalRegistry(Consumer<Meter> ignoredOnAddListener, Consumer<Meter> ignoredOnRemoveListener, boolean ignoredBackfill) Deprecated, for removal: This API element is subject to removal in a future version.since 27.0.0, for removal. Obtain the shared registry fromServices.get(MeterRegistry.class). Listeners can be enrolled with a custom registry usingcreateMeterRegistry(MetricsConfig, Consumer, Consumer).Returns this factory's globalMeterRegistry. The listeners and backfill setting are ignored and do not alter the global registry.- Parameters:
ignoredOnAddListener- ignored add listener; must not benullignoredOnRemoveListener- ignored remove listener; must not benullignoredBackfill- ignored backfill setting- Returns:
- this factory's global meter registry
-
metricsConfig
MetricsConfig metricsConfig()Returns theMetricsConfiginstance used to initialize the metrics factory.- Returns:
- metrics config used to create the metrics factory
-
meterRegistryBuilder
Returns a builder for creating a new caller-ownedMeterRegistry. The caller must close the registry created by the builder to release the registry and any publisher resources it owns.- Type Parameters:
B- specific type of the builderM- specific type of the registry- Returns:
- the new builder for a caller-owned registry
-
createMeterRegistry
Creates a new caller-ownedMeterRegistryusing the provided metrics config. The caller must close the returned registry to release the registry and any publisher resources it owns.- Parameters:
metricsConfig- metrics configuration which influences the new registry- Returns:
- new caller-owned meter registry
-
createMeterRegistry
MeterRegistry createMeterRegistry(MetricsConfig metricsConfig, Consumer<Meter> onAddListener, Consumer<Meter> onRemoveListener) Creates a new caller-ownedMeterRegistryusing the provided metrics config and enrolling the specified listeners with the returned meter registry. The caller must close the returned registry to release the registry and any publisher resources it owns.- Parameters:
metricsConfig- metrics configuration which influences the new registryonAddListener- invoked whenever a new meter is added to the meter registryonRemoveListener- invoked whenever a new meter is removed from the meter registry- Returns:
- new caller-owned meter registry with the listeners enrolled
-
createMeterRegistry
Creates a new caller-ownedMeterRegistryusing the providedClockandMetricsConfig. The caller must close the returned registry to release the registry and any publisher resources it owns.- Parameters:
clock- default clock to associate with the meter registrymetricsConfig- metrics configuration which influences the new registry- Returns:
- new caller-owned meter registry
-
createMeterRegistry
MeterRegistry createMeterRegistry(Clock clock, MetricsConfig metricsConfig, Consumer<Meter> onAddListener, Consumer<Meter> onRemoveListener) Creates a new caller-ownedMeterRegistryusing the providedClockandMetricsConfigand enrolling the specified listeners with the new meter registry. The caller must close the returned registry to release the registry and any publisher resources it owns.- Parameters:
clock- clock to associate with the meter registrymetricsConfig- metrics config which influences the new registryonAddListener- invoked whenever a new meter is added to the meter registryonRemoveListener- invoked whenever a new meter is removed from the meter registry- Returns:
- new caller-owned meter registry
-
clockSystem
-
counterBuilder
Creates a builder for aCounter.- Parameters:
name- name of the counter- Returns:
- counter builder
-
functionalCounterBuilder
<T> FunctionalCounter.Builder<T> functionalCounterBuilder(String name, T stateObject, Function<T, Long> fn) Creates a builder for a functionalCounter, essentially a counter-style wrapper around an external object.- Type Parameters:
T- type of the state object- Parameters:
name- name of the counterstateObject- object which provides the counter valuefn- function which, when applied to the state object, yields the counter value- Returns:
- counter builder
-
distributionStatisticsConfigBuilder
DistributionStatisticsConfig.Builder distributionStatisticsConfigBuilder()Creates a builder for aDistributionStatisticsConfig.- Returns:
- statistics config builder
-
distributionSummaryBuilder
DistributionSummary.Builder distributionSummaryBuilder(String name, DistributionStatisticsConfig.Builder configBuilder) Creates a builder for aDistributionSummary.- Parameters:
name- name of the summaryconfigBuilder- distribution stats config the summary should use- Returns:
- summary builder
-
gaugeBuilder
Creates a builder for a state-basedGauge.- Type Parameters:
T- type of the state object- Parameters:
name- name of the gaugestateObject- object which maintains the value to be exposed via the gaugefn- function which, when applied to the state object, returns the gauge value- Returns:
- gauge builder
-
gaugeBuilder
- Type Parameters:
N- subtype ofNumberwhich the supplier providers- Parameters:
name- gauge namesupplier- supplier for an instance of the specified subtype ofNumber- Returns:
- new builder
-
timerBuilder
Creates a builder for aTimer.- Parameters:
name- name of the timer- Returns:
- timer builder
-
timerStart
Timer.Sample timerStart()Returns aTimer.Samplefor measuring a duration using the system defaultClock.- Returns:
- new sample
-
timerStart
Returns aTimer.Samplefor measuring a duration, using the clock associated with the specifiedMeterRegistry.- Parameters:
registry- the meter registry whoseClockis to be used- Returns:
- new sample with the start time recorded
-
timerStart
Returns aTimer.Samplefor measuring a duration using the specifiedClock.- Parameters:
clock- the clock to use for measuring the duration- Returns:
- new sample
-
tagCreate
-
histogramSnapshotEmpty
Returns an empty histogram snapshot with the specified aggregate values.- Parameters:
count- counttotal- totalmax- max value- Returns:
- histogram snapshot
-
noOpMeter
Returns a no-opMeterof the type implied by the builder's runtime type, initialized with the builder's name and other required parameters.- Parameters:
builder- original builder- Returns:
- corresponding no-op meter
-