java.lang.Object
io.helidon.servicecommon.rest.HelidonRestServiceSupport
io.helidon.metrics.MetricsSupport
- All Implemented Interfaces:
MetricsSupport,RestServiceSupport,Service
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(Config). The following configuration parameters can be used:
| key | default value | description |
|---|---|---|
| helidon.metrics.context | /metrics | Context root under which the rest endpoints are available |
| helidon.metrics.base.${metricName}.enabled | true | Can 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());
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA fluent API builder to build instances ofMetricsSupport. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMetricsSupport(MetricsSettings metricsSettings, RestServiceSettings restServiceSettings) Creates a newMetricsSupportinstance from the provides settings.protectedMetricsSupport(MetricsSupport.Builder builder) Creates a newMetricsSupportinstance from the provided builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic MetricsSupport.Builderbuilder()Deprecated, for removal: This API element is subject to removal in a future version.voidconfigureVendorMetrics(String routingName, Routing.Rules rules) Configure vendor metrics on the provided routing.static MetricsSupportcreate()Create an instance to be registered with Web Server with all defaults.static MetricsSupportCreate an instance to be registered with Web Server maybe overriding default values with configured values.static MetricsSupportcreate(MetricsSettings metricsSettings, RestServiceSettings restServiceSettings) Create an instance to be registered with Web Server with the specific metrics settings.protected voidLogic to run when the service is shut down.protected voidpostConfigureEndpoint(Routing.Rules defaultRules, Routing.Rules serviceEndpointRoutingRules) Finish configuring metrics endpoint on the provided routing rules.voidprepareMetricsEndpoints(String endpointContext, Routing.Rules serviceEndpointRoutingRules) Prepares the family of/metricsendpoints.static StringtoPrometheusData(String name, Metric metric, boolean withHelpType) Formats a metric in Prometheus format.static StringtoPrometheusData(MetricID metricID, Metric metric, boolean withHelpType) Formats a metric in Prometheus format.voidupdate(Routing.Rules rules) Method invoked by the web server to update routing rules.Methods inherited from class io.helidon.servicecommon.rest.HelidonRestServiceSupport
configureEndpoint, context, loggerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.helidon.metrics.serviceapi.MetricsSupport
configureEndpoint
-
Constructor Details
-
MetricsSupport
Creates a newMetricsSupportinstance from the provided builder.- Parameters:
builder- the builder for preparing the new instance
-
MetricsSupport
Creates a newMetricsSupportinstance from the provides settings.- Parameters:
metricsSettings- the metrics settings to use in preparing theMetricsSupportinstancerestServiceSettings- rest services settings to use in preparing theMetricsSupportinstance
-
-
Method Details
-
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(MetricsSettings metricsSettings, RestServiceSettings restServiceSettings) Create an instance to be registered with Web Server with the specific metrics settings.- Parameters:
metricsSettings- metrics settings to use for initializing metricsrestServiceSettings- REST service settings for managing the endpoint- Returns:
- a new instance built with the specified metrics settings
-
create
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
Deprecated, for removal: This API element is subject to removal in a future version.UseMetricsSupport.builder()instead.Create a new builder to construct an instance.- Returns:
- A new builder instance
-
toPrometheusData
Formats a metric in Prometheus format.- Parameters:
metricID- theMetricIDfor the metric to be formattedmetric- theMetriccontaining the data to be formattedwithHelpType- flag controlling serialization of HELP and TYPE- Returns:
- metric info in Prometheus format
-
toPrometheusData
Formats a metric in Prometheus format.- Parameters:
name- the name of the metricmetric- theMetriccontaining the data to be formattedwithHelpType- flag controlling serialization of HELP and TYPE- Returns:
- metric info in Prometheus format
-
configureVendorMetrics
Configure vendor metrics on the provided routing. This method is exclusive toupdate(io.helidon.webserver.Routing.Rules)(e.g. you should not use both, as otherwise you would duplicate the metrics)- Specified by:
configureVendorMetricsin interfaceMetricsSupport- Parameters:
routingName- name of the routing (may be null)rules- routing builder or routing rules
-
postConfigureEndpoint
protected void postConfigureEndpoint(Routing.Rules defaultRules, Routing.Rules serviceEndpointRoutingRules) Finish configuring metrics endpoint on the provided routing rules. This method just adds the endpoint/metrics(or appropriate one as configured). For simple routings, just registerMetricsSupportinstance. This method is exclusive toupdate(io.helidon.webserver.Routing.Rules)(e.g. you should not use both, as otherwise you would register the endpoint twice)- Specified by:
postConfigureEndpointin classHelidonRestServiceSupport- Parameters:
defaultRules- routing rules for default routing (also acceptsRouting.Builder)serviceEndpointRoutingRules- possibly different rules for the metrics endpoint routing
-
prepareMetricsEndpoints
public void prepareMetricsEndpoints(String endpointContext, Routing.Rules serviceEndpointRoutingRules) Description copied from interface:MetricsSupportPrepares the family of/metricsendpoints.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.
- Specified by:
prepareMetricsEndpointsin interfaceMetricsSupport- Parameters:
endpointContext- context (typically /metrics)serviceEndpointRoutingRules- routing rules to update with the disabled metrics endpoints
-
update
Method invoked by the web server to update routing rules. Register this instance with webserver throughRouting.Builder.register(io.helidon.webserver.Service...)rather than calling this method directly. If multiple sockets (and routings) should be supported, you can use theHelidonRestServiceSupport.configureEndpoint(io.helidon.webserver.Routing.Rules, io.helidon.webserver.Routing.Rules), andconfigureVendorMetrics(String, io.helidon.webserver.Routing.Rules)methods.- Specified by:
updatein interfaceMetricsSupport- Specified by:
updatein interfaceService- Parameters:
rules- a routing rules to update
-
onShutdown
protected void onShutdown()Description copied from class:HelidonRestServiceSupportLogic to run when the service is shut down.- Overrides:
onShutdownin classHelidonRestServiceSupport
-
MetricsSupport.builder()instead.