Jonathan Jonathan - 1 month ago 9
Java Question

Can jconsole data be retrieved from the command line?

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

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

Comments