Reputation: 3534
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
Upvotes: 39
Views: 92675
Reputation: 139971
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.
Upvotes: 7
Reputation: 30449
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
Upvotes: 13
Reputation: 27707
You might find jvm-mon useful for this. It is a JVM monitoring tool for the command line that disaplys:
The metrics and charts update while the tool is open.
Upvotes: 4
Reputation: 1469
Some other useful CLI tools to monitor a Java applications are:
Upvotes: 6
Reputation: 15973
Maybe jvmtop is worth a look.
It's a command-line tool which provides a live-view for several metrics.
JvmTop 0.4.1 amd64 8 cpus, Linux 2.6.32-27, load avg 0.12
http://code.google.com/p/jvmtop
PID MAIN-CLASS HPCUR HPMAX NHCUR NHMAX CPU GC VM USERNAME #T DL
3370 rapperSimpleApp 165m 455m 109m 176m 0.12% 0.00% S6U37 web 21
11272 ver.resin.Resin [ERROR: Could not attach to VM]
27338 WatchdogManager 11m 28m 23m 130m 0.00% 0.00% S6U37 web 31
19187 m.jvmtop.JvmTop 20m 3544m 13m 130m 0.93% 0.47% S6U37 web 20
16733 artup.Bootstrap 159m 455m 166m 304m 0.12% 0.00% S6U37 web 46
Upvotes: 13
Reputation: 7932
You can use this jmx query tool by command line: http://crawler.archive.org/cmdline-jmxclient/
Upvotes: 8
Reputation: 26
I have successfully used the tomcat jmxproxy for access from scripts ( http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Using_the_JMX_Proxy_Servlet ).
I haven't used any of them but one of the jmx-rest projects might be an option for a non-tomcat server ( http://www.google.com/search?q=jmx+rest ).
Upvotes: 0
Reputation: 29679
This is a partial answer to your question:
set JAVA_OPTS=%JAVA_OPTS% -Xloggc:logs\gc.log -XX:+PrintGCDetails -XX:MaxPermSize=128m
Upvotes: 0