[JBOSS4][JMX] リモートJMXサーバの情報を取得する

JBOSSJMXサーバにリモートで接続して情報を取得する方法のメモ。

twiddleを利用する場合

JBOSS4には、twiddleというリモートJMXクライアントが提供されています。
これを使えば、リモートJMXサーバにアクセスすることができます。


例えば、現在のセッション数を取得したい場合

> cd D:\jboss-4.0.5.GA\bin
> twiddle.bat get "jboss.web:type=Manager,path=/struts-examples,host=localhost" activeSessions

activeSessions=0

なお、最後の属性名を指定しない場合には、すべての属性が取得できます。

> twiddle.bat get "jboss.web:type=Manager,path=/struts-examples,host=localhost"

modelerType=org.apache.catalina.session.StandardManager
algorithm=MD5
randomFile=/dev/urandom
className=org.apache.catalina.session.StandardManager
distributable=false
entropy=org.apache.catalina.session.StandardManager@1044daf
maxActiveSessions=-1
maxInactiveInterval=1800
processExpiresFrequency=6
sessionIdLength=16
name=StandardManager
pathname=
activeSessions=0
sessionCounter=1
maxActive=1
sessionMaxAliveTime=1803
sessionAverageAliveTime=1803
rejectedSessions=0
expiredSessions=1
processingTime=797
duplicates=0

JMXサーバに接続するソースを書く場合

以下のように書けばリモートJMXサーバにつないで属性を取得できます。

private static final String OBJECT_NAME = "jboss.web:host=localhost,path=/struts-examples,type=Manager";

try {
  Properties props = new Properties();
  props.put(Context.PROVIDER_URL, "localhost");
  props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  InitialContext ctx = new InitialContext(props);
  MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
  ctx.close();

  ObjectName objectName = new ObjectName(OBJECT_NAME);
  Object result = server.getAttribute(objectName, "activeSessions");
  System.out.println(result);
} catch (Exception e) {
  e.printStackTrace();
}

Web-Consoleを利用する場合

Web-Consoleを使う場合の手順は以下のとおりです。

  1. http://localhost:8080/web-console/にアクセス
  2. 左メニュー「System」-「JMX MBeans]を選択
  3. 右画面で「host=localhost,path=/struts-examples,type=Manager」というリンクを探す。

ActionSessionsやprocessingTimeなど、色々参照できます。




参考

  • 「The JBoss 4 Application Server Guide」-「2.3.3. Command Line Access to JMX
  • org.jboss.console.twiddle.command.GetCommand#execute()