问题描述
我目前正在使用 jconsole
来监控我的 Java 应用程序的性能指标,并且想要脚本这个数据采集.
I am currently using jconsole
to monitor performance metrics of my Java application and would like to script this data acquisition.
有没有办法将这些 VM 指标(堆内存使用率、线程数、CPU 使用率等)检索到 STDOUT
?top -p PID -b -n 1
中的数据并没有完全削减它.
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.
谢谢
推荐答案
jconsole
只是为平台 MBeanServer
中的 JMX MBean 提供了一个包装器.
jconsole
just provides a wrapper around the JMX MBeans that are in the platform MBeanServer
.
您可以编写一个程序来使用 附加 API 然后查询 MBean.
You can write a program to connect to your VM using the Attach API which would then query the MBeans.
或者您可以通过 RMI 公开平台 MBeanServer
并以这种方式查询 MBean.
Or you can expose the platform MBeanServer
over RMI and query the MBeans that way.
参见java.lang.management 包以获取更多信息
See the java.lang.management package for more info
这篇关于可以从命令行检索 jconsole 数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!