MetricsEndpoint

zio.http.metrics.MetricsEndpoint

One-stop shop for exposing Prometheus metrics over HTTP.

Instruments every route with request/response metrics and appends a /metrics endpoint that serves the Prometheus text format.

Server
 .serve(MetricsEndpoint.withMetrics(myRoutes))
 .provide(Server.default, MetricsEndpoint.layers())

Attributes

Source
MetricsEndpoint.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

A single route that serves Prometheus metrics. Use this if you want to handle instrumentation separately (e.g. with Middleware.metrics()).

A single route that serves Prometheus metrics. Use this if you want to handle instrumentation separately (e.g. with Middleware.metrics()).

Attributes

Source
MetricsEndpoint.scala
def layers(pollingInterval: Duration = ...): ZLayer[Any, Nothing, PrometheusPublisher]

Combined ZIO layers for Prometheus metrics. Provides PrometheusPublisher. Polls metrics at the specified interval (default: 1 second).

Combined ZIO layers for Prometheus metrics. Provides PrometheusPublisher. Polls metrics at the specified interval (default: 1 second).

Attributes

Source
MetricsEndpoint.scala
def withMetrics[Env](routes: Routes[Env, Response], metricsPath: String = ..., concurrentRequestsName: String = ..., totalRequestsName: String = ..., requestDurationName: String = ..., requestDurationBoundaries: Boundaries = ..., extraLabels: Set[MetricLabel] = ...)(implicit trace: Trace): Routes[Env & PrometheusPublisher, Response]

Instruments routes with HTTP metrics and appends a Prometheus endpoint.

Instruments routes with HTTP metrics and appends a Prometheus endpoint.

This is the recommended one-call API. It applies Middleware.metrics() to instrument your routes and appends a GET /metrics route that serves Prometheus-formatted metrics.

Value parameters

concurrentRequestsName

name of the gauge tracking concurrent requests

extraLabels

additional labels to attach to all metrics

metricsPath

the path at which to expose Prometheus metrics (default: "metrics")

requestDurationBoundaries

histogram bucket boundaries for request duration

requestDurationName

name of the histogram tracking request durations

routes

the application routes to instrument

totalRequestsName

name of the counter tracking total requests

Attributes

Source
MetricsEndpoint.scala