简体   繁体   English

如何使用 jmap 从 Kubernetes Pod 获取 Java 堆转储?

[英]How to get Java Heap Dump from a Kubernetes Pod using jmap?

I was following the steps mentioned here How to get a heap dump from Kubernetes k8s pod?我正在按照这里提到的步骤如何从 Kubernetes k8s pod 获取堆转储?

I'm able to get the the process id using top command inside the pod.我可以在 pod 内使用 top 命令获取进程 ID。 However, when I run jmap I get this:但是,当我运行 jmap 时,我得到了这个:

~ $ jmap
sh: jmap: not found

I access the pod with this command: kubectl exec -it -- sh我使用以下命令访问 pod:kubectl exec -it -- sh

I also tried this command:我也试过这个命令:

kubectl exec -it <pod> -- jmap -dump:live,format=b,file=heapdump.bin 1

But I was getting:但我得到:

OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"jmap\": executable file not found in $PATH": unknown command terminated with exit code 126

Is there any other way to get the java heap dump from the pod?有没有其他方法可以从 pod 中获取 Java 堆转储?

Normally containers are limited on the tools available(like you get 'more', but you don't get 'less'), so the tools available for you depends on your container.通常容器受限于可用的工具(比如你得到“更多”,但你不会得到“更少”),所以可供你使用的工具取决于你的容器。

The 2 tools that are used to get a heap dump are jmap and jcmd, check if you got jcmd in the container.用于获取堆转储的 2 个工具是 jmap 和 jcmd,检查容器中是否有 jcmd。

https://www.adam-bien.com/roller/abien/entry/taking_a_heap_dump_with https://www.adam-bien.com/roller/abien/entry/taking_a_heap_dump_with

If not, I recommend to put the java app in a container that has either jmap or jcmd and then run it;如果没有,我建议将 java 应用程序放在具有 jmap 或 jcmd 的容器中,然后运行它; even if the container is "heavier" that won't affect the java app nor the heap dump so it will be the same.即使容器“更重”,也不会影响 Java 应用程序或堆转储,因此它是相同的。

If that's not an option, maybe this will be https://techblog.topdesk.com/coding/extracting-a-heap-dump-from-a-running-openj9-java-process-in-kubernetes/ (not mine).如果这不是一个选项,也许这将是https://techblog.topdesk.com/coding/extracting-a-heap-dump-from-a-running-openj9-java-process-in-kubernetes/ (不是我的) .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM