scrape

suspend fun scrape(withTimestamp: Boolean = false): String

Scrapes all current metrics from the registry and encodes them in Prometheus text format.

This method is suspendable and safe to use in coroutine-based environments.

Example usage in a Ktor route:

get("/metrics") {
call.respondText(PrometheusExporter().scrape(), ContentType.Text.Plain)
}

Return

A string containing the full Prometheus-formatted exposition of all collected metrics.

Parameters

withTimestamp

If true, includes timestamps in the output for each sample.