Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (32 sloc) 1.23 KB
package cookbook.monitoring
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import org.http4k.client.ApacheClient
import org.http4k.core.Method.GET
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.core.then
import org.http4k.filter.MetricFilters
import org.http4k.routing.bind
import org.http4k.routing.routes
fun main() {
// this is a micrometer registry used mostly for testing - substitute the correct implementation.
val registry = SimpleMeterRegistry()
val server = routes("/metrics/{name}" bind GET to { Response(OK) })
// apply filters to a server...
val app = MetricFilters.Server.RequestCounter(registry)
// ... or to a client
val client =
// make some calls
(0..10).forEach {
app(Request(GET, "/metrics/$it"))
client(Request(GET, ""))
// see some results
registry.forEachMeter { println("${} ${it.measure().joinToString(",")}") }