Member-only story
Analysing Java GC in Kubernetes Without Stopping or Changing Anything
Get the current Java memory and GC without restarting with just kubectl exec or docker exec access

Do you run Java in Kubernetes or Docker and need to quickly analyze the Java memory and GC behavior without stopping the process/container?
Is the container running in a protected cluster on which you can only run kubectl and you can’t add JMX or other ports?
Are you running a Java-based container but don’t want to include jstat
or other tools?
Here’s a solution.
Note: this will work for any Java HotSpot based JVM.
This solution assumes an “airgap” environment (without internet access) and will allow you to achieve the following progressively:
- Quickly have a terminal-based glance at the current Java memory and GC metrics for a running container
(steps 1 to 3)

- Pipeline the Java memory and GC metrics gathered to a local Prometheus/Grafana setup to analyze them near real-time
(step 4)