How should I monitor a web application on tomcat using JMX?

I would like to monitor web applications running under tomcat using JMX.

I don't want to just use the built in JMX implementation of Tomcat, I want to implement an mbean for the actual Web Application so I can get information on application-specific settings and monitor it.

The problem with web applications and online monitoring is that web applications are not always active but are "awaken" to handle requests by the server so monitoring them is not just plugging in with JMX as I would for a normal running process.

How do you make Tomcat run applications in the background (Like a Singleton) so I can connect to it at all time?

Is there a way to do this that is common and I am not aware of?

Thanks!


You can create a class that implements ServletContextListener and then load that listener in your web.xml.

The class:

public class ServerListener implements ServletContextListener {

    public void contextDestroyed(ServletContextEvent pSce) {
    }

    public void contextInitialized(ServletContextEvent pSce) {
        // TODO Register MBean here.
    }
}

The web.xml:

<listener>
  <listener-class>com.example.ServerListener</listener-class>
</listener>

In your app you need to register the MBean with the MBean server when the application is deployed. While the web application is deployed, the MBean will be exposed. I have used the Spring Framework JMX support to do this within Tomcat - but there are are ways to do this without Spring.


if you are familiar with Nagios and your company is using it, that may be a better choice

These plugins do look helpful https://exchange.nagios.org/directory/Plugins/Java-Applications-and-Servers/Apache-Tomcat

Else as said by @teabot, use Spring JMX support. Makes it very easy.

链接地址: http://www.djcxy.com/p/59706.html

上一篇: JMX是正确的选择?

下一篇: 我应该如何使用JMX监视tomcat上的Web应用程序?