使用JMX(Java Management Extensions)API獲取活動會話計數

[英]Getting Active Session counts with JMX (Java Management Extensions) API


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

我正在嘗試使用JMX API來獲取Web應用程序的活動會話計數。

  1. Is it possible to use JMX API to get this kind of information?
  2. 是否可以使用JMX API來獲取此類信息?

  3. If yes, how reliable would it be?
  4. 如果是的話,它會有多可靠?

  5. Any example code on how to get this done?
  6. 有關如何完成此操作的任何示例代碼?

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.

我一直在閱讀JMX教程和文檔,但他們正在概述這項技術是什么。我還是無法確定我需要什么。

5 个解决方案

#1


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.

一旦配置應用服務器以公開JMX端口,就可以通過使用JConsole或JVisualVM之類的東西來實現此目的。您沒有提到您正在使用的應用服務器,但對於Tomcat,它在此處描述:http://tomcat.apache.org/tomcat-5.5-doc/monitoring.html。一旦與JConsole連接,Tomcat就會公開一個具有會話信息的MBean,但它又取決於您使用的容器。

#2


ObjectName name = new ObjectName("Catalina:type=Manager,path=/NAME_OF_APP,host=localhost"); 
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");

#3


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).

要跟蹤會話,您可以使用HttpSessionListener。如果要通過JMX公開活動會話,可以注冊mbean並從其他應用程序調用它(請參閱JMX文檔)。

#4


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.

JBoss已經通過JMX暴露了活動會話數,但是只在整個服務器上,而不是每個webapp。如果您只使用了一個webapp,那么這對您來說應該沒問題。

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.

在端口8080上轉到JMX控制台,並查找名為host = localhost,path = /,type = Manager的條目。在里面,你會找到一個活動會話計數的條目。

#5


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:

skaffman給出的答案非常有用,但我會修改JBoss能夠通過尋找以下內容為每個webapp提供會話:

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

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

(將your_webapp_context替換為您感興趣的webapp的上下文...)


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/07/10/72ff5761e18ec0b5d03279d8cec72bd4.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com