使用 JVisualVM 从 Java 中的远程应用程序获取堆转储

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/726643/
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-11 18:45:41  来源:igfitidea点击:

Get heap dump from a remote application in Java using JVisualVM

javamonitoringheapjvisualvm

提问by Philipp

I run JVisualVM (Windows XP, Sun Java 1.6.0.13, 32 bit client VM) to monitor a distant application (Linux, Sun Java 1.6.0.07, 64 bit server VM). Before starting the actual remote application, I launch on the remote machine jstatdusing an all access policy:

我运行 JVisualVM(Windows XP、Sun Java 1.6.0.13、32 位客户端 VM)来监视远程应用程序(Linux、Sun Java 1.6.0.07、64 位服务器 VM)。在启动实际的远程应用程序之前,我jstatd使用所有访问策略在远程机器上启动:

grant codebase "file:${java.home}/../lib/tools.jar" {
   permission java.security.AllPermission;
};

Then I start the actual app using the command line

然后我使用命令行启动实际的应用程序

 java -Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.port=3333 
compileTest.Main

From the client machine, I can see the distant app and monitor it. I can also make a thread dump etc. Unfortunately, the heap-dump button is grayed out.

在客户端机器上,我可以看到远处的应用程序并对其进行监控。我也可以进行线程转储等。不幸的是,堆转储按钮是灰色的。

How can I obtain a heap-dump from a remotely monitored application using JVisualVM?

如何使用 JVisualVM 从远程监控的应用程序获取堆转储?

I tried using jConsole. With jConsole it is possible to make a distantheap dump using the com.sun.management.HotSpotDiagnostic dumpHeap operation. I want the dump to be transferred to the client side and analyzed using the tools provided by JVisualVM. How can I do this?

我尝试使用 jConsole。使用 jConsole 可以使用 com.sun.management.HotSpotDiagnostic dumpHeap 操作进行远程堆转储。我希望将转储传输到客户端并使用 JVisualVM 提供的工具进行分析。我怎样才能做到这一点?

回答by Ichorus

You cannot analyze the heap remotely. You could run visualvm on your server and export the x session to your local machine. You would have to have x11 installed on your server which many servers do not.

您无法远程分析堆。您可以在您的服务器上运行 visualvm 并将 x 会话导出到您的本地机器。您必须在服务器上安装 x11,而许多服务器都没有。

回答by Yeroc

Unfortunately there isn't an automated way to do this. You'll have to run jmap manually on the Linux server to dump the heap of your JVM and then copy the resultant heap dump to your local machine running JVisualVM and use File|Load... to load the heap dump into JVisualVM for analysis.

不幸的是,没有一种自动化的方法可以做到这一点。您必须在 Linux 服务器上手动运行 jmap 以转储 JVM 的堆,然后将生成的堆转储复制到运行 JVisualVM 的本地计算机,并使用 File|Load... 将堆转储加载到 JVisualVM 中进行分析。

回答by Yeroc

There is a way to do it!

有一种方法可以做到!

  1. rmiregistry -J-Xbootclasspath/p:$JAVA_HOME/lib/sa-jdi.jar ( this uses port 1099)
  2. start 'jsadebugd' on the machine in which application is running: jsadebugd & (pid of JVM)
  3. On remote machine use following jmap -dump:file= :1099

  4. jhat

  1. rmir​​egistry -J-Xbootclasspath/p:$JAVA_HOME/lib/sa-jdi.jar(这里使用端口 1099)
  2. 在运行应用程序的机器上启动“jsadebugd”:jsadebugd &(JVM的pid)
  3. 在远程机器上使用以下 jmap -dump:file= :1099

  4. 杰哈特

The above will start a web application at port 7000

以上将在端口 7000 启动一个 web 应用程序

All the above tools are part of JDK 1.6

以上所有工具都是 JDK 1.6 的一部分

All the best!

祝一切顺利!

回答by Ko-Chih Wu

Since 1.3, VisualVM support remote heap dumps:

从 1.3 开始,VisualVM 支持远程堆转储:

Starting with VisualVM 1.3, you can now use the Heap Dump actions and buttons in the tool to take a heap dump of applications that are running remotely. When invoked, a dialog is displayed that enables you to specify the full path on the remote system where you want to dump the heap. After the heap dump is created, you need to manually copy the file to your local machine and use the Load action to open and analyze the file using VisualVM.

从 VisualVM 1.3 开始,您现在可以使用工具中的堆转储操作和按钮对远程运行的应用程序进行堆转储。调用时,会显示一个对话框,您可以在其中指定要转储堆的远程系统上的完整路径。创建堆转储后,您需要手动将文件复制到本地计算机,并使用 Load 操作使用 VisualVM 打开和分析文件。

See: VisualVM 1.3 Released

请参阅:VisualVM 1.3 发布