open source / metrics4s / integrations
Integrations
All four share the HTTP definitions in metrics4s-http, so one dashboard row fits whichever is used. Routes are
templates from a closed set, and status is a class (2xx, 4xx, failed).
scala
// http4s: the route templates and a classifier into them; anything else is "unmatched"
val middleware = Http4sServerMetrics[IO](List("GET /events/{id}", "POST /events"))(classify)
val client = Http4sClientMetrics[IO](httpClient, List("get-event"))(operationOf)
// tapir: the templates come from the endpoints
TapirMetrics[IO](endpoints).map(metrics => Http4sServerOptions.customiseInterceptors[IO].metricsInterceptor(metrics.interceptor))
// sttp client 4
SttpMetrics.register[IO](List("get-user")).map(recorder => SttpMetrics.wrap(backend, recorder)(operationOf))
// MongoDB driver, and mongo4s through MongoClientResource.fromSettings
MongoMetrics(List("users", "events")).register[IO].map(listeners => listeners.applyTo(MongoClientSettings.builder()).build())The same definitions are on the companions, with no routes or collections: HttpServerMetrics.requests, .duration
and .inFlight, the same three on HttpClientMetrics, the five of MongoMetrics, and definitions on each. A
dashboard needs the label names, not the values, so it draws from them without the service's route list:
scala
Stats(
Stat.rate(HttpServerMetrics.requests),
Stat.quantile(HttpServerMetrics.duration, 0.95),
Stat.share(HttpServerMetrics.requests)(_.status.in(StatusClass.ServerError, StatusClass.Failed)),
)
dashboard.missingSeries(List(ProcessorMetrics.processed, ProcessorMetrics.processTime) ++ HttpServerMetrics.definitions)| Module | Metrics |
|---|---|
metrics4s-http4s, metrics4s-tapir |
http_server_requests_total{route, status}, http_server_request_seconds{route}, http_server_in_flight |
metrics4s-http4s, metrics4s-sttp |
http_client_requests_total{operation, status}, http_client_request_seconds{operation}, http_client_in_flight |
metrics4s-mongo |
mongo_command_seconds{command, collection}, mongo_command_failures_total{command, collection}, mongo_pool_connections{state}, mongo_pool_checkout_seconds, mongo_pool_checkout_failures_total{reason} |
built from README.md at v0.2.0
edit this page on GitHub