我应该如何使用 JMX 监控 tomcat 上的 Web 应用程序?

发布于 2024-08-01 14:05:56 字数 322 浏览 5 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哆兒滾 2024-08-08 14:05:56

在您的应用程序中,您需要在部署应用程序时向 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.

五里雾 2024-08-08 14:05:56

您可以创建一个实现 ServletContextListener 的类,然后在 web.xml 中加载该侦听器。

类:

public class ServerListener implements ServletContextListener {

    public void contextDestroyed(ServletContextEvent pSce) {
    }

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

web.xml:

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

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>
迷鸟归林 2024-08-08 14:05:56

如果您熟悉 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文