Can jconsole data be retrieved from the command line?

Jonathan picture Jonathan · Jul 28, 2009 · Viewed 75.2k times · Source

I am currently using jconsole to monitor performance metrics of my Java application and would like to script this data acquisition.

Is there a way to retrieve these VM metrics (heap memory usage, thread count, CPU usage etc.) to STDOUT?
The data in top -p PID -b -n 1 doesn't quite cut it.

Thanks

Answer

Kevin picture Kevin · Jul 28, 2009

jconsole just provides a wrapper around the JMX MBeans that are in the platform MBeanServer.

You can write a program to connect to your VM using the Attach API which would then query the MBeans.

Or you can expose the platform MBeanServer over RMI and query the MBeans that way.

See the java.lang.management package for more info