问题
I need to create a container level JMX MBean for tomcat servers to allow enterprise level monitoring of a few custom features.
The examples I am finding online are focused on webapp level MBeans. I found a few examples for Tomcat 5, but it looks like a lot has changed since then.
How can I register an MBean for an entire Tomcat instance?
回答1:
Tomcat already have MBeans for monitoring stuff. You need to enable it via CATALINA_OPTS, just add:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port={port to access}
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
And then connect to that port via JConsole or VisualVM. Read further.
回答2:
I solved by adding the required descriptor AND putting a listener in web.xml for the container. It was necessary to test whether bean already existed in this sceario, since the listener is called for each app in the container.
来源:https://stackoverflow.com/questions/29473344/container-level-custom-jxm-mbean-in-tomcat-7