Class MetricsObserver
java.lang.Object
io.helidon.webserver.observe.metrics.MetricsObserver
- All Implemented Interfaces:
RuntimeType.Api<MetricsObserverConfig>,NamedService,Observer
public class MetricsObserver
extends Object
implements Observer, RuntimeType.Api<MetricsObserverConfig>
Support for metrics for Helidon WebServer.
By default, creates the /metrics endpoint with three sub-paths: application,
vendor and base.
To register with web server, discovered from classpath:
Routing.builder()
.register(ObserveFeature.create())
See ObserveFeature.just(io.helidon.webserver.observe.spi.Observer...)
to customize observer setup.
This class supports finer grained configuration using Helidon Config:
create(io.helidon.common.config.Config).
The application metrics registry is then available as follows:
req.context().get(MetricRegistry.class).ifPresent(reg -> reg.counter("myCounter").inc());
-
Method Summary
Modifier and TypeMethodDescriptionbuilder()Create a new builder to configure Metrics observer.voidConfigure Helidon specific metrics.static MetricsObservercreate()Create a new Metrics observer with default configuration.static MetricsObserverCreate a new Metrics observer from configuration.static MetricsObservercreate(MetricsObserverConfig config) Create a new Metrics observer using the provided configuration.static MetricsObservercreate(Consumer<MetricsObserverConfig.Builder> consumer) Create a new Metrics observer customizing its configuration.Configuration of this observer.voidregister(ServerFeature.ServerFeatureContext featureContext, List<HttpRouting.Builder> observeEndpointRouting, UnaryOperator<String> endpointFunction) Register the observer features, services, and/or filters.type()Type of this observer, to make sure we do not configure an observer both fromServiceLoaderand using programmatic approach.
-
Method Details
-
builder
Create a new builder to configure Metrics observer.- Returns:
- a new builder
-
create
Create a new Metrics observer using the provided configuration.- Parameters:
config- configuration- Returns:
- a new observer
-
create
Create a new Metrics observer customizing its configuration.- Parameters:
consumer- configuration consumer- Returns:
- a new observer
-
create
Create a new Metrics observer with default configuration.- Returns:
- a new observer
-
create
Create a new Metrics observer from configuration.- Parameters:
config- configuration of this observer- Returns:
- a new observer
-
prototype
Description copied from interface:ObserverConfiguration of this observer.- Specified by:
prototypein interfaceObserver- Specified by:
prototypein interfaceRuntimeType.Api<MetricsObserverConfig>- Returns:
- configuration of the observer
-
type
Description copied from interface:ObserverType of this observer, to make sure we do not configure an observer both fromServiceLoaderand using programmatic approach. If it is desired to have more than one observer of the same type, always use programmatic approach- Specified by:
typein interfaceNamedService- Specified by:
typein interfaceObserver- Returns:
- type of this observer, should match
ObserveProvider.type()
-
register
public void register(ServerFeature.ServerFeatureContext featureContext, List<HttpRouting.Builder> observeEndpointRouting, UnaryOperator<String> endpointFunction) Description copied from interface:ObserverRegister the observer features, services, and/or filters. This is used by the observe feature. Do NOT use this method directly, kindly start withObserveFeatureand register it with the server builder.- Specified by:
registerin interfaceObserver- Parameters:
featureContext- access to all routing builders, for cases where this observer needs to register additional components to other socketsobserveEndpointRouting- routing builders that expose observability endpoints, and this feature must use these to register any endpoints exposed for observabilityendpointFunction- function to obtain the final endpoint for observers that expose observe endpoints (such as/observe/healthwould be provider forhealthby default)
-
configureVendorMetrics
Configure Helidon specific metrics.- Parameters:
rules- rules to use
-