Monday, October 29, 2007

JVM Monitoring using JMX

We can manage Java applications through JMX API. Java supports JMX from jdk1.5 onwards. JConsole is a tool for monitoring local or remote JVMs. This entirely works on JMX technology. To do what JConsole does we need to write a JMX client. This client would get access to the MBean exposed by JVM by connecting to the JMX Agent in that JVM.

How to write a client is explained clearly by this blog [1]. We can modify the code given in the blog to access the memory usage details of the JVM. We have to gain access to the MemoryMXBean[2].

There are some issues which have to be taken care of when running the application to be monitored.[3] The java application should be run using the following parameters:

-Dcom.sun.management.jmxremote.port=5009
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

The Remote Client connects to a JMX agent using an RMI connector with the following URL: [4] service:jmx:rmi:///jndi/rmi://hostName:5009/jmxrmi.



References:

[1] http://blogs.sun.com/jmxetc/entry/how_to_retrieve_remote_jvm
[2] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/MemoryMXBean.html
[3] http://72.5.124.55/javase/6/docs/technotes/guides/management/agent.html
[4] http://forum.java.sun.com/thread.jspa?threadID=5212843

No comments: