使用 JMX(Java 管理扩展)API 获取活动会话计数

发布于 2024-07-27 03:42:18 字数 200 浏览 5 评论 0原文

我正在尝试使用 JMX API 获取 Web 应用程序的活动会话计数。

  1. 是否可以使用JMX API来获取此类信息?
  2. 如果是的话,可信度如何?
  3. 有关于如何完成此操作的示例代码吗?

我一直在阅读 JMX 教程和文档,但它们让我概述了该技术是什么。 我只是还不能确定我需要什么。

I'm trying to use JMX API to get active session counts for a web application.

  1. Is it possible to use JMX API to get this kind of information?
  2. If yes, how reliable would it be?
  3. Any example code on how to get this done?

I've been reading JMX tutorial and documentation, but they are giving me the overview of what the technology is. I just can't pinpoint to what I need, yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

最偏执的依靠 2024-08-03 03:42:18

一旦您将应用程序服务器配置为公开 JMX 端口,您就可以使用 JConsole 或 JVisualVM 之类的工具来完成此操作。 您没有提及您正在使用哪个应用程序服务器,但对于 Tomcat,其描述如下: http://tomcat.apache.org/tomcat-5.5-doc/monitoring.html。 连接 JConsole 后,Tomcat 会公开一个包含会话信息的 MBean,但这又取决于您使用的容器。

You can accomplish this by using something like JConsole or JVisualVM once you configure your app server to expose a JMX port. You don't mention which app server you're using but for Tomcat, it's described here: http://tomcat.apache.org/tomcat-5.5-doc/monitoring.html. Once you connect with JConsole, Tomcat exposes an MBean which has session information but again it depends which container you use.

庆幸我还是我 2024-08-03 03:42:18
ObjectName name = new ObjectName("Catalina:type=Manager,path=/NAME_OF_APP,host=localhost"); 
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");
ObjectName name = new ObjectName("Catalina:type=Manager,path=/NAME_OF_APP,host=localhost"); 
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");
a√萤火虫的光℡ 2024-08-03 03:42:18

要跟踪会话,您可以使用 HttpSessionListener 。 如果您想通过 JMX 公开活动会话,您可以注册一个 mbean 并从其他应用程序调用它(请参阅 JMX 文档)。

To track the sessions you could use an HttpSessionListener . If you want to expose the active sessions via JMX, you could register a mbean and call it from other applications(see JMX documentation).

烟花易冷人易散 2024-08-03 03:42:18

JBoss 已经通过 JMX 公开了活动会话计数,但仅限于整个服务器,而不是每个 Web 应用程序。 如果您只使用一个网络应用程序,那么这对您来说应该没问题。

转到端口 8080 上的 JMX 控制台,并查找名为 host=localhost,path=/,type=Manager 的条目。 在其中您将找到活动会话计数的条目。

JBoss already exposes the active session count via JMX, but only across the whole server, not per webapp. If you only have one webapp being used, then that should be OK for you.

Go the JMX console on port 8080, and look for the entry called host=localhost,path=/,type=Manager. Inside that you'll find a entry for active session count.

独留℉清风醉 2024-08-03 03:42:18

skaffman给出的答案非常有帮助,但我想修改一下,JBoss能够通过查找以下内容为每个web应用程序提供会话:

host = localhost,path = / your_webapp_context,type = Manager

(将your_webapp_context替换为您的web应用程序的上下文)有兴趣...)

The answer given by skaffman is quite helpful, but I would amend that JBoss is able to give you the sessions per webapp by looking for:

host=localhost,path=/your_webapp_context,type=Manager

(replace your_webapp_context with the context of the webapp you are interested in...)

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