Reputation: 113
I have more than one java application running in separate docker containers. I am trying to collect monitoring data such as GC log, thread dump, heap dump from the java process running inside a container using tools like jstat, jstack, jmap. Is it possible to capture this information from the host(outside containers)?
I am new to the containerized world. I understand that PID namespace of the host and container is different. When I execute jstack <PID> > thread_dump.txt
from the host, it shows error message: Unable to open socket file /proc/root/tmp/.java_pid: target process doesn't respond within 10500ms or HotSpot VM not loaded
Where PID is process id from the host PID namespace.
When I execute jstack
inside container ( docker exec -it <container_id_or_name>
) then it is able to capture thread dump.
Where PID is process id from the container PID namespace.
Any hints on how to solve this?
Upvotes: 1
Views: 3787
Reputation: 98630
jattach tool serves exactly for this purpose. The project is free and open source.
Examples:
jattach <pid> threaddump
(works like jstack)jattach <pid> inspectheap
(works like jmap -histo)jattach <pid> jcmd GC.class_stats
where <pid>
is Java process ID in the host namespace.
As a bonus, jattach
works even if container runs JRE with no JDK tools (jstack, jcmd, etc.) installed.
Upvotes: 4
Reputation: 11050
The command you should use is:
docker exec -i <container_id_or_name> <your_monitoring_command>
The command will be executed inside the container, but it will report its output (by -i
) to the caller console.
Upvotes: 1