Java 可以从命令行检索 jconsole 数据吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1193954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can jconsole data be retrieved from the command line?
提问by Jonathan
I am currently using jconsole
to monitor performance metrics of my Java application and would like to scriptthis data acquisition.
我目前jconsole
用于监控我的 Java 应用程序的性能指标,并希望编写此数据采集的脚本。
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.
有没有办法将这些 VM 指标(堆内存使用率、线程数、CPU 使用率等)检索到STDOUT
?
中的数据top -p PID -b -n 1
并没有完全削减它。
Thanks
谢谢
采纳答案by Kevin
jconsole just provides a wrapper around the JMX MBeans that are in the platform MBeanServer.
jconsole 只是为平台 MBeanServer 中的 JMX MBean 提供了一个包装器。
You can write a program to connect to your VM using the Attach APIwhich would then query the MBeans.
您可以编写一个程序来使用附加 API连接到您的 VM ,然后该程序将查询 MBean。
Or you can expose the platform MBeanServer over RMI and query the MBeans that way.
或者,您可以通过 RMI 公开平台 MBeanServer 并以这种方式查询 MBean。
See the java.lang.managementpackage for more info
有关更多信息,请参阅java.lang.management包
回答by matt b
Take a look at jmap
, which can be used to take a heap dump from the console.
看看jmap
,它可用于从控制台获取堆转储。
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.
对于堆转储中未涵盖的数据,我相信 jconsole 只是使用 JMX 连接到正在运行的 JVM 来获取统计信息——因此很可能创建您自己的应用程序,该应用程序可以从 JMX 中提取相同类型的统计信息。
回答by Sbodd
回答by djangofan
This is a partial answer to your question:
这是对您问题的部分回答:
set JAVA_OPTS=%JAVA_OPTS% -Xloggc:logs\gc.log -XX:+PrintGCDetails -XX:MaxPermSize=128m
回答by llama
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).
我已经成功地使用 tomcat jmxproxy 从脚本访问(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).
我没有使用过它们中的任何一个,但 jmx-rest 项目之一可能是非 tomcat 服务器的一个选项(http://www.google.com/search?q=jmx+rest)。
回答by user2427
You can use this jmx query tool by command line: http://crawler.archive.org/cmdline-jmxclient/
您可以通过命令行使用这个 jmx 查询工具:http: //crawler.archive.org/cmdline-jmxclient/
回答by Tonin
回答by MRalwasser
Maybe jvmtopis worth a look.
It's a command-line tool which provides a live-viewfor several metrics.
也许jvmtop值得一看。
它是一个命令行工具,可为多个指标提供实时视图。
Example output of the VM overview mode:
VM 概览模式的示例输出:
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