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

情到浓时终转凉″ 提交于 2019-12-21 05:51:51

问题


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!


回答1:


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>



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1287658/how-should-i-monitor-a-web-application-on-tomcat-using-jmx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!