I would like to monitor the embedded Tomcat in my Spring Boot Service. Spring itself gives me some session usage stats, but I need additional information about the underlying thread pool like active connections, queue length etc.
I've searched the registered beans but can't find the thread pool that is used.
Any thoughts on how to retrieve that information?
Hi question from 18 months ago!
So, turns out the embedded Tomcat metrics are pretty easy to monitor with Spring Boot 2.0 and its new Metrics package. A reason to upgrade that app.
Here's some sample code to get you started.
class SomeClass {
@Autowired
private MeterRegistry repo;
@ReadOperation
public WebEndpointResponse<Map> invoke() {
Gauge busyThreads = repo.get("tomcat.threads.busy").gauge();
Gauge allThreads = repo.get("tomcat.threads.config.max").gauge(); // yes, could do @Value("${server.tomcat.max-threads:200}") and have it injected
double busyThreadsCount = busyThreads.value();
double allThreadsCount = allThreads.value();
....
}
}
See more:
TomcatMetrics
class asks Tomcat for it specifically, so it shouldn't be too too hard to pull that into a Spring Boot 1.x actuator.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With