我应该如何使用 JMX 监控 tomcat 上的 Web 应用程序?
我想使用 JMX 监视在 tomcat 下运行的 Web 应用程序。
我不想只使用 Tomcat 的内置 JMX 实现,我想为实际的 Web 应用程序实现一个 mbean,这样我就可以获得有关特定于应用程序的设置的信息并对其进行监视。
Web 应用程序和在线监控的问题在于,Web 应用程序并不总是处于活动状态,而是“唤醒”以处理服务器的请求,因此监控它们不仅仅是像正常运行进程那样插入 JMX。
如何让 Tomcat 在后台运行应用程序(就像单例)以便我可以随时连接到它?
有没有一种常见但我不知道的方法可以做到这一点?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的应用程序中,您需要在部署应用程序时向 MBean 服务器注册 MBean。 部署 Web 应用程序时,MBean 将被公开。 我已经使用 Spring Framework JMX 支持 来做这在 Tomcat 中 - 但有一些方法可以在没有 Spring 的情况下做到这一点。
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.
您可以创建一个实现 ServletContextListener 的类,然后在 web.xml 中加载该侦听器。
类:
web.xml:
You can create a class that implements
ServletContextListener
and then load that listener in your web.xml.The class:
The web.xml:
如果您熟悉 Nagios 并且您的公司正在使用它,那可能是更好的选择
这些插件看起来确实很有帮助
https://exchange.nagios.org/directory/ Plugins/Java-Applications-and-Servers/Apache-Tomcat
否则,正如 @teabot 所说,使用 Spring JMX 支持。 使它变得非常容易。
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.