java.lang.Object
io.helidon.nima.servicecommon.HelidonFeatureSupport
io.helidon.nima.observe.metrics.MetricsFeature
All Implemented Interfaces:
FeatureSupport, HttpFeature, ServerLifecycle, Supplier<HttpFeature>

public class MetricsFeature extends HelidonFeatureSupport
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 MetricsFeature 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 MetricsFeature 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 MetricsFeature.Builder builder()
      Create a new builder to construct an instance.
      Returns:
      a new builder instance
    • service

      public Optional<HttpService> service()
      Description copied from interface: FeatureSupport
      If this feature is represented by a service, return it here, to simplify implementation. Otherwise you will need to implement FeatureSupport.setup(HttpRouting.Builder, HttpRouting.Builder).
      Returns:
      service if implemented
    • configureVendorMetrics

      public void configureVendorMetrics(HttpRouting.Builder rules)
      Configure Helidon specific metrics.
      Parameters:
      rules - rules to use
    • beforeStart

      public void beforeStart()
      Description copied from interface: ServerLifecycle
      Before server start.
    • afterStop

      public void afterStop()
      Description copied from interface: ServerLifecycle
      After server stop.
    • postSetup

      protected void postSetup(HttpRouting.Builder defaultRouting, HttpRouting.Builder featureRouting)
      Description copied from class: HelidonFeatureSupport
      This can be used to register services, filters etc. on either the default rules (usually the main routing of the web server) and the feature routing (may be the same instance). If FeatureSupport.service() provides an instance, that instance will be correctly registered with the context root on feature routing.
      Overrides:
      postSetup in class HelidonFeatureSupport
      Parameters:
      defaultRouting - default HttpRules to be updated
      featureRouting - actual rules (if different from the default ones) to be updated for the service endpoint