MetricsService
A Guava GenericIdleService that runs an embedded Jetty server to expose a Prometheus PrometheusMetricsServlet.
The service starts a Jetty HTTP server on the specified port and serves the Prometheus metrics endpoint at the given path. It also exposes a healthCheck property for integration with Dropwizard health check registries.
The servlet negotiates the exposition format through the request's Accept header: a plain scrape (no Accept, or one that does not ask for OpenMetrics) gets the Prometheus text format (Content-Type starting text/plain; version=0.0.4), and a scrape sending Accept: application/openmetrics-text; version=1.0.0 gets the OpenMetrics text format instead.
The metrics are served without authentication unless filters add it: every request, including one for a path other than path, passes through the filters in list order first, and a filter can answer it itself, for example with a 401. Jetty initializes the filters when the server starts, and a filter that fails to initialize fails the start; it destroys them when the server stops. Starting a server that binds every interface (a host such as "0.0.0.0" or "::") logs a WARN.
Parameters
The HTTP port for the metrics endpoint.
The URL path for the Prometheus metrics servlet, with or without a leading slash.
The interface to bind to. The default, null, binds 127.0.0.1, so only local clients can connect; use "0.0.0.0" to accept connections on every interface, such as scrapes from another host or container.
The PrometheusRegistry to serve. Defaults to PrometheusRegistry.defaultRegistry.
The servlet filters every request passes through, in order, before it reaches the metrics servlet.
An optional initialization block invoked after the service listener is registered.