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.

This is not intended to be the interface which developers use to work with Helidon metrics. Instead use

An implementation of this interface provides instance methods for each of the static methods on the Helidon metrics API interfaces. The prefix of each method here identifies the interface that bears the corresponding static method. For example, timerStart(io.helidon.metrics.api.MeterRegistry) corresponds to the static Timer.start(io.helidon.metrics.api.MeterRegistry) method.

Also, various static methods create new instances or return previously-created ones.

  • Method Details

    • getInstance

      static MetricsFactory getInstance()
      Returns the most-recently created implementation or, if none, a new one from a highest-weight provider available at runtime and using the "metrics" section from the GlobalConfig.
      Returns:
      current or new metrics factory
    • getInstance

      static MetricsFactory getInstance(Config metricsConfigNode)
      Returns a new metrics factory instance from a highest-weight provider using the provided Config to set up the metrics factory and saving the resulting metrics factory as the current one, returned by getInstance()}.
      Parameters:
      metricsConfigNode - metrics config node
      Returns:
      new instance configured as directed
    • closeAll

      static void closeAll()
      Closes all MetricsFactory instances.

      Applications do not normally need to invoke this method.

    • close

      void close()
      Closes this metrics factory.

      Applications do not normally need to invoke this method.

    • globalRegistry

      MeterRegistry globalRegistry()
      Returns the global MeterRegistry for this metrics factory.

      The metric factory creates its global registry on-demand using getInstance().createMeterRegistry(MetricsConfig) with a MetricsConfig instance derived from the root Config most recently passed to getInstance(io.helidon.common.config.Config), or if none then the config from GlobalConfig.

      Returns:
      the global meter registry
    • globalRegistry

      MeterRegistry globalRegistry(MetricsConfig metricsConfig)
      Creates a new global registry according to the configuration and returns it.
      Parameters:
      metricsConfig - configuration to control the meter registry
      Returns:
      meter registry
    • globalRegistry

      MeterRegistry globalRegistry(Consumer<Meter> onAddListener, Consumer<Meter> onRemoveListener, boolean backfill)
      Returns the global MeterRegistry enrolling the specified listeners to the meter registry.
      Parameters:
      onAddListener - invoked whenever a new meter is added to the returned meter registry
      onRemoveListener - invoked whenever a meter is removed from the returned meter registry
      backfill - whether the meter registry should invoke the on-add listener for meters already present in an existing global registry
      Returns:
      on-demand global registry with the indicated listeners added
    • 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 MeterRegistry.
      Type Parameters:
      B - specific type of the builder
      M - specific type of the registry
      Returns:
      the new builder
    • createMeterRegistry

      MeterRegistry createMeterRegistry(MetricsConfig metricsConfig)
      Creates a new MeterRegistry using the provided metrics config.
      Parameters:
      metricsConfig - metrics configuration which influences the new registry
      Returns:
      new meter registry
    • createMeterRegistry

      MeterRegistry createMeterRegistry(MetricsConfig metricsConfig, Consumer<Meter> onAddListener, Consumer<Meter> onRemoveListener)
      Creates a new MeterRegistry using the provided metrics config and enrolling the specified listeners with the returned meter registry.
      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 meter registry with the listeners enrolled
    • createMeterRegistry

      MeterRegistry createMeterRegistry(Clock clock, MetricsConfig metricsConfig)
      Creates a new MeterRegistry using the provided Clock and MetricsConfig.
      Parameters:
      clock - default clock to associate with the meter registry
      metricsConfig - metrics configuration which influences the new registry
      Returns:
      new meter registry
    • createMeterRegistry

      MeterRegistry createMeterRegistry(Clock clock, MetricsConfig metricsConfig, Consumer<Meter> onAddListener, Consumer<Meter> onRemoveListener)
      Creates a new MeterRegistry using the provided Clock and MetricsConfig and enrolling the specified listners with the new meter registry.
      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 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