Example of embedded Jetty and using Micrometer for stats (without Spring)

Viewed 459

I am new to using Micrometer as a metrics/stats producer and I am having a hard time in getting it configured correctly with my Jersey/Embedded Jetty server. I would like to get Jetty statistics added.

I already have the servlet producing stats for the JVM in a Prometheus format.

Does anyone know of a good working example on how to configure it?

I am not using SpringBoot.

1 Answers

The best way is to look at the Spring Boot code. For example it binds the jetty connections

JettyConnectionMetrics.addToAllConnectors(server, this.meterRegistry, this.tags);

And it uses an ApplicationStartedEvent to find the server reference.

private Server findServer(ApplicationContext applicationContext) {
    if (applicationContext instanceof WebServerApplicationContext) {
        WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
        if (webServer instanceof JettyWebServer) {
            return ((JettyWebServer) webServer).getServer();
        }
    }
    return null;
}

There are other classes that record the thread usage and SSL handshake metrics.

Related