Class MetricsSupport

All Implemented Interfaces:
RestServiceSupport, Service

public class MetricsSupport extends HelidonRestServiceSupport
Support for metrics for Helidon Web Server.

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

To register with web server:


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

This class supports finer grained configuration using Helidon Config: create(io.helidon.config.Config). The following configuration parameters can be used:

Configuration parameters
keydefault valuedescription
helidon.metrics.context/metricsContext root under which the rest endpoints are available
helidon.metrics.base.${metricName}.enabledtrueCan control which base metrics are exposed, set to false to disable a base metric

The application metrics registry is then available as follows:


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

    • create

      public static MetricsSupport create()
      Create an instance to be registered with Web Server with all defaults.
      Returns:
      a new instance built with default values (for context, base metrics enabled)
    • create

      public static MetricsSupport create(Config config)
      Create an instance to be registered with Web Server maybe overriding default values with configured values.
      Parameters:
      config - Config instance to use to (maybe) override configuration of this component. See class javadoc for supported configuration keys.
      Returns:
      a new instance configured withe config provided
    • builder

      public static MetricsSupport.Builder builder()
      Create a new builder to construct an instance.
      Returns:
      a new builder instance
    • update

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

      protected void postConfigureEndpoint(Routing.Rules defaultRules, Routing.Rules serviceEndpointRoutingRules)
      Description copied from class: HelidonRestServiceSupport
      Concrete implementations override this method to perform any service-specific routing set-up.
      Specified by:
      postConfigureEndpoint in class HelidonRestServiceSupport
      Parameters:
      defaultRules - default Routing.Rules to be updated
      serviceEndpointRoutingRules - actual rules (if different from the default ones) to be updated for the service endpoint
    • onShutdown

      protected void onShutdown()
      Overrides:
      onShutdown in class HelidonRestServiceSupport