Get GC log data from the Docker container using jstat

1.7k Views Asked by At

I have a java application running inside a docker container with OpenJDK11. I want to get GC data from this application using jstat tool (available inside a container). Any idea how can I achieve this from the host or another container running on the same host?

Thank you :)

1

There are 1 best solutions below

1
the8472 On

The processes are visible on the host, so jstat -gcstat <pid> works on the host if you know the pid as it is seen by the host.

You can get the host-pid of a container-pid-1 via docker inspect -f '{{.State.Pid}}' <container name> and then walk the process tree (e.g. via /proc or some library encapsulating that logic) to find the java child process and then call jstat.

Another option is to (partially) join the container's namespace via nsenter or docker exec and then just execute jps and jstat inside the container. But that can be a security concern if you don't trust the container.