Can jconsole data be retrieved from the command li

2019-01-14 15:08发布

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

9条回答
贼婆χ
2楼-- · 2019-01-14 15:37

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

查看更多
看我几分像从前
3楼-- · 2019-01-14 15:38

Some other useful CLI tools to monitor a Java applications are:

  • Jmxterm which gives full access to all MBeans on the application server, runs interactively or not,
  • jmxbox which can only connect through a TCP socket, not directly to a local process with its PID
查看更多
姐就是有狂的资本
4楼-- · 2019-01-14 15:39

This is a partial answer to your question:

set JAVA_OPTS=%JAVA_OPTS% -Xloggc:logs\gc.log -XX:+PrintGCDetails -XX:MaxPermSize=128m 
查看更多
男人必须洒脱
5楼-- · 2019-01-14 15:46

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.

查看更多
Animai°情兽
6楼-- · 2019-01-14 15:50

You can use this jmx query tool by command line: http://crawler.archive.org/cmdline-jmxclient/

查看更多
放我归山
7楼-- · 2019-01-14 15:56

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 ).

查看更多
登录 后发表回答