2010-12-07

Using VisualVM with IBM JDK []

Moved to the page http://3rdstage.wikia.com/wiki/J2EE_Application_Tuning in my wiki as of 5th Oct. 2012.

You can use JMX to monitoring IBM JDK with VisualVM.
Java SE 5.0 introduced platform MBeanServer and IBM Java SDK 5.0 or higher naturally provide it. Platform MBeanServer includes various basic managed beans about memory, thread, garbage collection, class loading and so on[1]. VisualVM can show such information with visual views.

Basically remote access of platform MBeanServer is not activated. You can enable it in several ways.
If you can control the start-up of the VM, you can enable remote access of platform MBeanServer by setting com.sun.management.jmxremote.por system property in command line to launch VM. If you are in position where you can control the system properties, you can programmatically load JMX connector server and expose it using RMI registry.

Method 1. Enabling built-in JMX agent using system properties

You can enable built-in JMX agent of Java runtime with the following system properties explicitly in start-up command of JVM.

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

With VisualVM, you should add new local or remote application using [File > Add JMX Connection] menu item. The connection string has the form of hostname:port such as localhost:3333 or 203.201.71.31:3333.

For more about built-in JMX agent, refer readings 2 below. If more secure setup for remote access to the platform MBeanServer is necessary, it would be really helpful.



Method 2. Exposing platform MBeanServer using JMXConnectorServer programmatically.

When you can not control the start-up command of the JVM, you can expose platform MBeanServer through JMXConnectorServer instance in your code. The JMXConnectorServer should be exposed using RMI registry.

The following code sample shows core steps, acquiring platform MBeanServer, creating JMXConnectorServer instance, creating RMI registry and starting JMXConnectorServer.

   ...

   //acquiring platform MBeanServer
   MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 

   //creating JMXConnectorServer instance
   JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" 
         + InetAddress.getLocalHost().getHostAddress() + ":9999/server");
   JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
  
   //creating RMI registry
   Registry reg = LocateRegistry.createRegistry(9999);
  
   //starting JMXConnectorServer
   cs.start();

   ...

With VisualVM, you should add new local or remote application using [File > Add JMX Connection] menu item. The connection string has the form of service:jmx:rmi:///jndi/rmi://host-address:port/service such as service:jmx:rmi:///jndi/rmi://203.201.71.31:9999/server.
Now you can identify JVM argument or system properties, monitor memory or garbage collection, class loading statistics, thread in timeline, and so on with VisualVM.

If you want stop the remote access to the platform MBeanServer programmatically, just stop the JMXConnectorSever.

   ...

   //stoping JMXConnectorServer
   cs.stop();

   //unload RMI registry
   java.rmi.server.UnicastRemoteObject.unexportObject(reg,true);

   ...

As for me, the above code worked with IBM Java SDK 6.0 on Windows and IBM Java SDK 6.0 64bit on AIX 6.2.

Readings

  1. java.lang.management package API
  2. Monitoring and Management Using JMX
  3. Connecting to JMX Agents Explicitly
  4. Support for the Java Attach API of IBM Java v6 on AIX

3 comments:

Vasile said...

Do You know if there's a jstatd server available for IBM J9 for AIX ? This in order to not fiddle with Portal startup settings just for monitoring

Vasile said...

And thanks for the guide, it seems to be the only thing that would work on AIX

Igor Livshin said...

Well, the main problem is that jstatd is not available on IBM JDK. Without jstatd many of these monitoring tools or plugins (like VisuaGC) don't work.

Post a Comment