MetricsService

class MetricsService(port: Int, path: String, host: String? = null, registry: PrometheusRegistry = PrometheusRegistry.defaultRegistry, initBlock: MetricsService.() -> Unit = {}) : GenericIdleService

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.

Parameters

port

The HTTP port for the metrics endpoint.

path

The URL path for the Prometheus metrics servlet, with or without a leading slash.

host

The interface to bind to, or null to bind every interface.

registry

The PrometheusRegistry to serve. Defaults to PrometheusRegistry.defaultRegistry.

initBlock

An optional initialization block invoked after the service listener is registered.

Constructors

Link copied to clipboard
constructor(port: Int, path: String, host: String? = null, registry: PrometheusRegistry = PrometheusRegistry.defaultRegistry, initBlock: MetricsService.() -> Unit = {})

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val healthCheck: HealthCheck

A Dropwizard HealthCheck that reports healthy when the embedded Jetty server is running.

Link copied to clipboard

Functions

Link copied to clipboard
fun addListener(listener: Service.Listener?, executor: Executor?)
Link copied to clipboard
fun awaitRunning(timeout: Duration?)
fun awaitRunning(timeout: Long, unit: TimeUnit?)
Link copied to clipboard
fun awaitTerminated(timeout: Duration?)
fun awaitTerminated(timeout: Long, unit: TimeUnit?)
Link copied to clipboard
Link copied to clipboard
@CanIgnoreReturnValue
fun startAsync(): Service?
Link copied to clipboard
fun startSync(timeout: Duration)
fun startSync(timeout: Duration)
Link copied to clipboard
fun state(): Service.State?
Link copied to clipboard
@CanIgnoreReturnValue
fun stopAsync(): Service?
Link copied to clipboard
fun stopSync(timeout: Duration)
fun stopSync(timeout: Duration)
Link copied to clipboard
open override fun toString(): String