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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:45:00  来源:igfitidea点击:

Can jconsole data be retrieved from the command line?

javaperformancecommand-linemonitoringjconsole

提问by Jonathan

I am currently using jconsoleto 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 1doesn'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

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

jstack在其正常输出中提供了许多有用的信息。堆内存使用直接可用,按GC区域细分;线程数可以通过一点 perl / grep / 等来确定。

回答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

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

其他一些用于监视 Java 应用程序的有用 CLI 工具是:

  • Jmxtermwhich gives full access to all MBeans on the application server, runs interactively or not,
  • jmxboxwhich can only connect through a TCP socket, not directly to a local process with its PID
  • Jmxterm提供对应用服务器上所有 MBean 的完全访问权限,是否交互运行,
  • jmxbox只能通过 TCP 套接字连接,不能直接连接到具有其 PID 的本地进程

回答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

回答by Andrejs

You might find jvm-monuseful for this. It is a JVM monitoring tool for the command line that disaplys:

您可能会发现jvm-mon对此很有用。它是一个用于命令行的 JVM 监控工具,它显示:

  • jvm processes
  • cpu and GC usage
  • heap usage and size
  • top threads
  • jvm进程
  • cpu 和 GC 使用率
  • 堆使用和大小
  • 顶线

The metrics and charts update while the tool is open.

工具打开时,指标和图表会更新。

Sample: jvm-mon

样本: jvm-mon