HashiCorp Nomad 如何从 java app 运行 获取堆转储?

How to get heap dump from java app running by HashiCorp Nomad?

我有 java HashiCorp Nomad 的 运行 申请。在进程状态输出中,我有 root 的游牧执行程序进程 运行 和 nobody 的 java 应用程序进程 运行。

当我尝试执行命令时: jmap -dump:format=b,file=filename.bin <app_pid>

我收到消息:

Unable to open socket file: target process not responding or HotSpot VM not loaded The -F option can be used when the target process is not responding

当我尝试执行命令时:jmap -dump:format=b,file=filename.bin <app_pid> -F

我得到了下一条线索:

Attaching to core -F from executable 5584, please wait... Error attaching to core file: cannot open binary file sun.jvm.hotspot.debugger.DebuggerException: cannot open binary file at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method) at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:286) at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:673) at sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:611) at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:337) at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304) at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:156) at sun.jvm.hotspot.tools.Tool.start(Tool.java:191) at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118) at sun.jvm.hotspot.tools.HeapDumper.main(HeapDumper.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.tools.jmap.JMap.runTool(JMap.java:201) at sun.tools.jmap.JMap.main(JMap.java:130)

没有 -F 的

jmap 应该由与目标 Java 进程相同的用户 运行(在您的情况下为 nobody)。

jmap -F 应该是根 运行,并且 -F 参数应该在 <app_pid>:

之前
jmap -dump:format=b,file=filename.bin -F <app_pid>

详见this answers