Package io.helidon.metrics
Class MetricsSupport
- java.lang.Object
-
- io.helidon.metrics.MetricsSupport
-
- All Implemented Interfaces:
Service
public final class MetricsSupport extends Object implements Service
Support for metrics for Helidon Web Server.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:Configuration parameters 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 Classes Modifier and Type Class Description static class
MetricsSupport.Builder
A fluent API builder to build instances ofMetricsSupport
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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(String name, Metric metric, boolean withHelpType)
Formats a metric in Prometheus format.static String
toPrometheusData(MetricID metricID, Metric metric, boolean withHelpType)
Formats a metric in Prometheus format.void
update(Routing.Rules rules)
Method invoked by the web server to update routing rules.
-
-
-
Method Detail
-
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
-
toPrometheusData
public static String toPrometheusData(MetricID metricID, Metric metric, boolean withHelpType)
Formats a metric in Prometheus format.- Parameters:
metricID
- theMetricID
for the metric to be formattedmetric
- theMetric
containing the data to be formattedwithHelpType
- flag controlling serialization of HELP and TYPE- Returns:
- metric info in Prometheus format
-
toPrometheusData
public static String toPrometheusData(String name, Metric metric, boolean withHelpType)
Formats a metric in Prometheus format.- Parameters:
name
- the name of the metricmetric
- theMetric
containing the data to be formattedwithHelpType
- flag controlling serialization of HELP and TYPE- Returns:
- metric info in Prometheus format
-
configureVendorMetrics
public void configureVendorMetrics(String routingName, Routing.Rules rules)
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)- Parameters:
routingName
- name of the routing (may be null)rules
- routing builder or routing rules
-
configureEndpoint
public void configureEndpoint(Routing.Rules rules)
Configure metrics endpoint on the provided routing rules. This method just adds the endpoint/metrics
(or appropriate one as configured). For simple routings, just registerMetricsSupport
instance. 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)- Parameters:
rules
- routing rules (also acceptsRouting.Builder
-
update
public void update(Routing.Rules rules)
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 theconfigureEndpoint(io.helidon.webserver.Routing.Rules)
, andconfigureVendorMetrics(String, io.helidon.webserver.Routing.Rules)
methods.
-
-