views:

1136

answers:

5

I currently use 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

A: 

Take a look at jmap, which can be used to take a heap dump from the console.

For data not covered in the heap dump, I believe jconsole just uses JMX to connect to the running JVM to get statistics - so it's likely possible to create your own application which could pull those same types of stats from JMX.

matt b
A: 

jstack offers a number of useful bits of information in its normal output. Heap memory usage is directly available, broken down by GC region; thread count could be determined with a little bit of perl / grep / etc.

Sbodd
+2  A: 

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

Kevin
A: 

This is a partial answer to your question:

set JAVA_OPTS=%JAVA_OPTS% -Xloggc:logs\gc.log -XX:+PrintGCDetails -XX:MaxPermSize=128m
djangofan