tags:

views:

512

answers:

2

Hi,

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!

A: 

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.

teabot
+1  A: 

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>
Peter D
Looks Good. I'm gonna try this now.
Ben
I'm trying to do this - http://oss.wxnet.org/mbeans.html.Hopefully this will work.
Ben