Monitor Tomcats internal threadpool without using JMX in a Spring Boot App
Asked Answered
I

0

0

I have a simple Spring Boot web application set up for handling incoming http requests.

Using the Java VisualVm I am able to see MBeans such as Tomcat's internal Threadpool. See the following screenshot:

Screenshot of the Java VisualVM's MBean viewer

I have successfully used JMX to monitor attributes such as "currentThreadCount" and "currentThreadsBusy". I set up Prometheus to access the monitored attributes as well. This works well.

However, now I wanted to know if it is possible to access these values without using JMX? I noticed that the abstract class https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/tomcat/util/net/AbstractEndpoint.html contains a method called getCurrentThreadCount(). The class Nio2Endpoint (https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/tomcat/util/net/Nio2Endpoint.html) extends AbstractEndpoint. So I imagine that this might be a way to retrieve these values.

Unfortunately I am not able to access the endpoints in any way. Can anybody tell me if it is possible at all to access them without using JMX?

Thank you very much!

Izaak answered 25/1, 2018 at 10:36 Comment(4)
Those are Tomcat internal classes, they're not accessible to your webapp. You would have to actually build your own version of Tomcat to access those classes.Gilles
Thank you very much. I was afraid I would have to change actual Tomcat source code in order to access them. Is there anything that I can do with Java reflection to help me out?Izaak
Is there a reason why you don't want to use a standard way of accessing that information, i.e. JMX? Trying to access the container classes from your webapp would be a really ugly hack, that is if you succeeded in it.Gilles
Mainly out of curiousity. While JMX works well for the task, I was wondering if there was another way. I'm successfully using a custom Prometheus controller for collecting Tomcat JDBC Connection Pool statistics (autowiring org.apache.tomcat.jdbc.pool.DataSource) and I was wondering if could do something similar with Tomcat's internal thread pool.Izaak

© 2022 - 2024 — McMap. All rights reserved.