Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vert.x tcp server with prometheus metrics
fun main() {
// init prometheus registry
val registry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
// bind micrometer metrics
ClassLoaderMetrics().bindTo(registry)
JvmMemoryMetrics().bindTo(registry)
JvmGcMetrics().bindTo(registry)
ProcessorMetrics().bindTo(registry)
JvmThreadMetrics().bindTo(registry)
UptimeMetrics().bindTo(registry)
FileDescriptorMetrics().bindTo(registry)
// create custom counter metric for packets received
Counter.builder("packets.received")
.description("number of reports added")
.baseUnit(BaseUnits.TASKS)
.register(registry)
// set up vertx options to report tcp metrics and start an embedded http server on port 9999
val vertxOptions = VertxOptions().setMetricsOptions(
MicrometerMetricsOptions()
.setPrometheusOptions(
VertxPrometheusOptions().setEnabled(true)
.setStartEmbeddedServer(true)
.setEmbeddedServerOptions(HttpServerOptions().setPort(9999))
.setEmbeddedServerEndpoint("/metrics")
)
.setMicrometerRegistry(registry)
.setEnabled(true)
)
val vertx = Vertx.vertx(vertxOptions)
// start our tcp server
vertx.createNetServer().connectHandler { it.handler { registry.counter("packets.received").increment() } }
.listen(9091)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.