installPrometheusMetrics

fun Application.installPrometheusMetrics(exporter: PrometheusExporter = PrometheusExporter(), configure: PrometheusConfig.() -> Unit = {})

Installs Prometheus metrics collection into the Ktor Application.

This function sets up instrumentation to collect HTTP request metrics and exposes them via a configurable HTTP endpoint for Prometheus to scrape.

Metrics collected:

  • http_requests_total{method, path}: total count of all HTTP requests received

  • http_requests_errors_total{method, status_code, path}: total count of HTTP error responses (status 400-500)

  • http_exceptions_total{method, path, exception_class}: total count of exceptions thrown during request handling

Endpoint:

Parameters

exporter

Optional PrometheusExporter instance to use for metrics registration and scraping. Defaults to a new exporter with the default collector registry.

configure

Lambda to configure PrometheusConfig options such as endpoint path and exposure.