Interface MetricsSupport

All Superinterfaces:
RestServiceSupport, Service
All Known Implementing Classes:
MetricsSupport, MinimalMetricsSupport

public interface MetricsSupport extends RestServiceSupport, Service
Behavior for supporting metrics for the Helidon Web Server.

By default, MetricsSupport creates the /metrics endpoint with three sub-paths: application, vendor, and base.

To register these endpoints with the web server:


 Routing.builder()
        .register(MetricsSupport.create())
 

This class supports finer-grained settings using MetricsSettings and RestServiceSettings and Helidon Config via create(io.helidon.metrics.api.MetricsSettings, io.helidon.servicecommon.rest.RestServiceSettings).

During request handling the application metrics registry is then available as follows:


  req.context().get(MetricRegistry.class).ifPresent(reg -> reg.counter("myCounter").inc());
 
  • Method Details

    • create

      static MetricsSupport create()
      Creates a new MetricsSupport instance using default metrics settings.
      Returns:
      new metrics support using default metrics settings
    • create

      static MetricsSupport create(MetricsSettings metricsSettings, RestServiceSettings restServiceSettings)
      Creates a new MetricsSupport instance using the specified metrics settings and REST service settings.
      Parameters:
      metricsSettings - metrics settings to use in initializing the metrics support
      restServiceSettings - REST service settings for the metrics endpoint
      Returns:
      new metrics support using specified metrics settings and REST service settings
    • create

      static MetricsSupport create(MetricsSettings metricsSettings)
      Creates a new MetricsSupport instance using the specified metrics settings and defaulted REST service settings.
      Parameters:
      metricsSettings - metrics settings to use in initializing the metrics support
      Returns:
      new metrics support using the specified metrics settings
    • create

      static MetricsSupport create(Config config)
      Creates a new MetricsSupport instance using the specified configuration.
      Parameters:
      config - configuration to use
      Returns:
      new metrics support instance using the provided configuration
    • builder

      static MetricsSupport.Builder<?,?> builder()
      Returns a builder for the highest-priority MetricsSupport implementation.
      Returns:
      builder for MetricsSupport
    • defaultedMetricsRestServiceSettingsBuilder

      static RestServiceSettings.Builder defaultedMetricsRestServiceSettingsBuilder()
      Prepares a RestServiceSettings.Builder instance for metrics with the default settings.
      Returns:
      the prepared builder
    • prepareMetricsEndpoints

      void prepareMetricsEndpoints(String endpointContext, Routing.Rules serviceEndpointRoutingRules)
      Prepares the family of /metrics endpoints.

      By default, requests to the metrics endpoints trigger a 404 response with an explanatory message that metrics are disabled. Implementations of this interface can provide more informative endpoints.

      Parameters:
      endpointContext - context (typically /metrics)
      serviceEndpointRoutingRules - routing rules to update with the disabled metrics endpoints
    • configureEndpoint

      void configureEndpoint(Routing.Rules defaultRoutingRules, Routing.Rules serviceEndpointRoutingRules)
      Prepares the endpoint which the service exposes.
      Specified by:
      configureEndpoint in interface RestServiceSupport
      Parameters:
      defaultRoutingRules - routing rules for the default routing
      serviceEndpointRoutingRules - routing rules (if different from default) for the service endpoint
    • configureVendorMetrics

      void configureVendorMetrics(String routingName, Routing.Rules routingRules)
      Sets up vendor metrics routing using the specified routing name and routing builder.
      Parameters:
      routingName - routing name to use in setting up the vendor metrics
      routingRules - routing rules to modify
    • update

      void update(Routing.Rules rules)
      Description copied from interface: Service
      Updates Routing.Rules with handlers representing this service.
      Specified by:
      update in interface Service
      Parameters:
      rules - a routing rules to update