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 Details

    • PULL_PUBLISHERS_PRESENT

      @Deprecated(since="27.0.0", forRemoval=true) static final String 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(since="27.0.0", forRemoval=true) static MetricsFactory getInstance()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 27.0.0, for removal. Use Services.get(MetricsFactory.class) for the shared metrics factory, or create non-global metrics objects using the programmatic API.
      Returns the shared metrics factory from Services.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. Use Services.get(MetricsFactory.class) for the shared metrics factory, or create non-global metrics objects using the programmatic API.
      Returns the shared metrics factory from Services.get(MetricsFactory.class).
      Parameters:
      ignoredConfig - ignored config; must not be null
      Returns:
      shared metrics factory
    • closeAll

      @Deprecated(since="27.0.0", forRemoval=true) static void 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(since="27.0.0", forRemoval=true) MeterRegistry 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 from Services.get(MeterRegistry.class). This method remains for metrics implementation compatibility.
      Returns the global MeterRegistry for 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 from Services.get(MeterRegistry.class). To create a non-global registry with custom configuration, use createMeterRegistry(MetricsConfig).
      Returns this factory's global registry. The configuration is ignored and does not alter the global registry.
      Parameters:
      ignoredMetricsConfig - ignored configuration; must not be null
      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 from Services.get(MeterRegistry.class). Listeners can be enrolled with a custom registry using createMeterRegistry(MetricsConfig, Consumer, Consumer).
      Returns this factory's global MeterRegistry. The listeners and backfill setting are ignored and do not alter the global registry.
      Parameters:
      ignoredOnAddListener - ignored add listener; must not be null
      ignoredOnRemoveListener - ignored remove listener; must not be null
      ignoredBackfill - ignored backfill setting
      Returns:
      this factory's global meter registry
    • metricsConfig

      MetricsConfig metricsConfig()
      Returns the MetricsConfig instance used to initialize the metrics factory.
      Returns:
      metrics config used to create the metrics factory
    • meterRegistryBuilder

      <B extends MeterRegistry.Builder<B,M>, M extends MeterRegistry> B meterRegistryBuilder()
      Returns a builder for creating a new caller-owned MeterRegistry. 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 builder
      M - specific type of the registry
      Returns:
      the new builder for a caller-owned registry
    • createMeterRegistry

      MeterRegistry createMeterRegistry(MetricsConfig metricsConfig)
      Creates a new caller-owned MeterRegistry using 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-owned MeterRegistry using 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 registry
      onAddListener - invoked whenever a new meter is added to the meter registry
      onRemoveListener - invoked whenever a new meter is removed from the meter registry
      Returns:
      new caller-owned meter registry with the listeners enrolled
    • createMeterRegistry

      MeterRegistry createMeterRegistry(Clock clock, MetricsConfig metricsConfig)
      Creates a new caller-owned MeterRegistry using the provided Clock and MetricsConfig. 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 registry
      metricsConfig - 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-owned MeterRegistry using the provided Clock and MetricsConfig and 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 registry
      metricsConfig - metrics config which influences the new registry
      onAddListener - invoked whenever a new meter is added to the meter registry
      onRemoveListener - invoked whenever a new meter is removed from the meter registry
      Returns:
      new caller-owned meter registry
    • clockSystem

      Clock clockSystem()
      Returns the system Clock from the underlying metrics implementation.
      Returns:
      the system clock
    • counterBuilder

      Counter.Builder counterBuilder(String name)
      Creates a builder for a Counter.
      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 functional Counter, essentially a counter-style wrapper around an external object.
      Type Parameters:
      T - type of the state object
      Parameters:
      name - name of the counter
      stateObject - object which provides the counter value
      fn - function which, when applied to the state object, yields the counter value
      Returns:
      counter builder
    • distributionStatisticsConfigBuilder

      DistributionStatisticsConfig.Builder distributionStatisticsConfigBuilder()
      Creates a builder for a DistributionStatisticsConfig.
      Returns:
      statistics config builder
    • distributionSummaryBuilder

      DistributionSummary.Builder distributionSummaryBuilder(String name, DistributionStatisticsConfig.Builder configBuilder)
      Creates a builder for a DistributionSummary.
      Parameters:
      name - name of the summary
      configBuilder - distribution stats config the summary should use
      Returns:
      summary builder
    • gaugeBuilder

      <T> Gauge.Builder<Double> gaugeBuilder(String name, T stateObject, ToDoubleFunction<T> fn)
      Creates a builder for a state-based Gauge.
      Type Parameters:
      T - type of the state object
      Parameters:
      name - name of the gauge
      stateObject - object which maintains the value to be exposed via the gauge
      fn - function which, when applied to the state object, returns the gauge value
      Returns:
      gauge builder
    • gaugeBuilder

      <N extends Number> Gauge.Builder<N> gaugeBuilder(String name, Supplier<N> supplier)
      Creates a builder for a Gauge based on a supplier of a subtype of Number.
      Type Parameters:
      N - subtype of Number which the supplier providers
      Parameters:
      name - gauge name
      supplier - supplier for an instance of the specified subtype of Number
      Returns:
      new builder
    • timerBuilder

      Timer.Builder timerBuilder(String name)
      Creates a builder for a Timer.
      Parameters:
      name - name of the timer
      Returns:
      timer builder
    • timerStart

      Timer.Sample timerStart()
      Returns a Timer.Sample for measuring a duration using the system default Clock.
      Returns:
      new sample
    • timerStart

      Timer.Sample timerStart(MeterRegistry registry)
      Returns a Timer.Sample for measuring a duration, using the clock associated with the specified MeterRegistry.
      Parameters:
      registry - the meter registry whose Clock is to be used
      Returns:
      new sample with the start time recorded
    • timerStart

      Timer.Sample timerStart(Clock clock)
      Returns a Timer.Sample for measuring a duration using the specified Clock.
      Parameters:
      clock - the clock to use for measuring the duration
      Returns:
      new sample
    • tagCreate

      Tag tagCreate(String key, String value)
      Creates a Tag from the specified key and value.
      Parameters:
      key - tag key
      value - tag value
      Returns:
      new Tag instance
    • histogramSnapshotEmpty

      HistogramSnapshot histogramSnapshotEmpty(long count, double total, double max)
      Returns an empty histogram snapshot with the specified aggregate values.
      Parameters:
      count - count
      total - total
      max - max value
      Returns:
      histogram snapshot
    • noOpMeter

      default Meter noOpMeter(Meter.Builder<?,?> builder)
      Returns a no-op Meter of 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