public final class MetricsSupport extends Object implements Service
By defaults cretes 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());
| Modifier and Type | Class and Description |
|---|---|
static class |
MetricsSupport.Builder
A fluent API builder to build instances of
MetricsSupport. |
| Modifier and Type | Method and Description |
|---|---|
static MetricsSupport.Builder |
builder()
Create a new builder to construct an instance.
|
void |
configureEndpoint(Routing.Rules rules)
Configure metrics endpoint on the provided routing rules.
|
void |
configureVendorMetrics(String routingName,
Routing.Rules rules)
Configure vendor metrics on the provided routing.
|
static MetricsSupport |
create()
Create an instance to be registered with Web Server with all defaults.
|
static MetricsSupport |
create(Config config)
Create an instance to be registered with Web Server maybe overriding default values with
configured values.
|
static String |
toPrometheusData(Metric metric)
Returns the Prometheus data for the specified
Metric. |
void |
update(Routing.Rules rules)
Method invoked by the web server to update routing rules.
|
public static MetricsSupport create()
public static MetricsSupport create(Config config)
config - Config instance to use to (maybe) override configuration of this component. See class javadoc for supported
configuration keys.public static MetricsSupport.Builder builder()
public static String toPrometheusData(Metric metric)
Metric.
Not every Metric supports conversion to Prometheus data. This
method checks the metric first before performing the conversion,
throwing an IllegalArgumentException if the metric cannot be
converted.
metric - the Metric to convert to Prometheus formatString containing the Prometheus datapublic void configureVendorMetrics(String routingName, Routing.Rules rules)
update(io.helidon.webserver.Routing.Rules)
(e.g. you should not use both, as otherwise you would duplicate the metrics)routingName - name of the routing (may be null)rules - routing builder or routing rulespublic void configureEndpoint(Routing.Rules rules)
/metrics (or appropriate
one as configured).
For simple routings, just register MetricsSupport instance.
This method is exclusive to update(io.helidon.webserver.Routing.Rules)
(e.g. you should not use both, as otherwise you would register the endpoint twice)rules - routing rules (also accepts Routing.Builderpublic void update(Routing.Rules rules)
Routing.Builder.register(io.helidon.webserver.Service...)
rather than calling this method directly.
If multiple sockets (and routings) should be supported, you can use
the configureEndpoint(io.helidon.webserver.Routing.Rules), and
configureVendorMetrics(String, io.helidon.webserver.Routing.Rules) methods.Copyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.