register_plumber_metrics {openmetrics}R Documentation

Metrics for Plumber APIs

Description

Automatically wrap a Plumber API app, adding metrics for HTTP request count and duration, and then expose them on a ⁠/metrics⁠ endpoint.

The endpoint will check the METRICS_HTTP_AUTHORIZATION environment variable, and if present will use it as the expected Authorization header of the request to the ⁠/metrics⁠ endpoint. This can be used to implement basic HTTP authentication for access to runtime metrics.

Usage

register_plumber_metrics(app, registry = global_registry())

Arguments

app

A Plumber router object.

registry

A Registry object. See registry().

Value

A modified Plumber router.

Examples

if (requireNamespace("plumber", quietly = TRUE)) {
  app <- plumber::plumber$new() # Normally this is plumber::plumb().
  app <- register_plumber_metrics(app)
## Not run: 
  app$run()

## End(Not run)
}

[Package openmetrics version 0.3.0 Index]