使用 JMX(Java 管理扩展)API 获取活动会话计数
我正在尝试使用 JMX API 获取 Web 应用程序的活动会话计数。
- 是否可以使用JMX API来获取此类信息?
- 如果是的话,可信度如何?
- 有关于如何完成此操作的示例代码吗?
我一直在阅读 JMX 教程和文档,但它们让我概述了该技术是什么。 我只是还不能确定我需要什么。
I'm trying to use JMX API to get active session counts for a web application.
- Is it possible to use JMX API to get this kind of information?
- If yes, how reliable would it be?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一旦您将应用程序服务器配置为公开 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.
要跟踪会话,您可以使用 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).
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.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...)