org.zalando.axiom.web.krueger.KruegerRouter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-krueger Show documentation
Show all versions of vertx-krueger Show documentation
This library creates vertx web endpoints exposing application metrics that can be consumed by Krueger (https://github.com/zalando/krueger-cockpit)
package org.zalando.axiom.web.krueger
import com.codahale.metrics.MetricRegistry
import io.vertx.core.AsyncResultHandler
import io.vertx.core.Future
import io.vertx.core.Vertx
import io.vertx.core.json.Json
import io.vertx.core.json.JsonObject
import io.vertx.ext.web.Router
import org.apache.logging.log4j.LogManager
import org.zalando.axiom.web.SwaggerRouter
import org.zalando.axiom.web.krueger.metrics.AppMetricsSupplier
import org.zalando.axiom.web.krueger.metrics.GarbageCollectorMetricsSupplier
import org.zalando.axiom.web.krueger.metrics.JvmMetricsSupplier
import org.zalando.axiom.web.krueger.metrics.ZmonMetricsSupplier
import java.util.*
object KruegerRouter {
val log = LogManager.getLogger(javaClass)
val swaggerJson = "operations-swagger.json"
fun create(vertx: Vertx, metricsRegistry: MetricRegistry = MetricRegistry(),
metricsSuppliers: List = listOf(ZmonMetricsSupplier(metricsRegistry), JvmMetricsSupplier(), GarbageCollectorMetricsSupplier())): Router {
val factory = SwaggerRouter.configure()
.collectMetricsTo(metricsRegistry)
.mapper(Json.mapper)
.swaggerDefinition("/$swaggerJson")
val appMetricsService = AppMetricsService(vertx, metricsSuppliers)
val vertxMetricsService = VertxMetricsService(vertx, metricsRegistry)
val router =
factory.bindTo("/metrics")
.get { handler: AsyncResultHandler