How to collect and get connection pool statistics using jetty and spring boot?

时光总嘲笑我的痴心妄想 提交于 2021-02-11 14:39:46

问题


I'm developing simple Spring Boot web application with embedded Jetty server.

I'd like to have some statistics on connection pool usage (i.e. how many threads, avg request time. avg queue wait time, queue size etc.)

I realized that Spring Boot configures Jetty with QueuedThreadPool which has few basic metrics. Is there more sophisticated bean or module designated for statistics collecting in Spring Boot? How to enable it?


回答1:


Have you had a look at Spring boot actuator? It provides you with some production ready features like a health endpoint and metrics endpoint. Just have a look at the documentation https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html




回答2:


There is a MonitoredQueuedThreadPool implementation that collects stats. The code below enables it and exposes via JMX:

@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(@Value("${server.port:8080}") final String port) {

    JettyEmbeddedServletContainerFactory factory =  new JettyEmbeddedServletContainerFactory(Integer.valueOf(port));

    //enable thread pool with stats
    factory.setThreadPool(new MonitoredQueuedThreadPool());

    //enable JMX
    factory.addServerCustomizers(server -> {
        MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        server.addEventListener(mbContainer);
        server.addBean(mbContainer);
        server.addBean(Log.getLog());

    });

    return factory;
}

JMX bean is exposed under node:

It provides metrics:



来源:https://stackoverflow.com/questions/57406631/how-to-collect-and-get-connection-pool-statistics-using-jetty-and-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!