Diagnostics Collector
The hard part of measuring is collecting. This script runs inside your container (kubectl exec -it <pod> -- sh, JDK image required), captures the diagnostics below in one shot, and tells you which jvm.expert page each file pastes into. A failed capture never aborts the rest.
#!/bin/sh
# jvm.expert diagnostics collector — run inside the container (kubectl exec -it <pod> -- sh).
# Needs a JDK image (jcmd on the PATH). If pgrep picks the wrong process, run with PID=<pid>.
PID=${PID:-$(pgrep -f java | head -1)}
if [ -z "$PID" ]; then echo "No java process found — re-run with PID=<pid>."; exit 1; fi
echo "Collecting JVM diagnostics for PID $PID..."
# NMT: the JVM must have been STARTED with -XX:NativeMemoryTracking=summary
# (it cannot be enabled on a running process — restart required if this fails).
jcmd "$PID" VM.native_memory summary > nmt.txt 2>&1 || echo "NMT capture failed — was -XX:NativeMemoryTracking=summary set at startup?"
# Class histogram: triggers a full GC-like walk; expect a brief pause.
jcmd "$PID" GC.class_histogram > histogram.txt 2>&1 || echo "Histogram capture failed."
jcmd "$PID" Thread.print > threads.txt 2>&1 || echo "Thread dump failed."
# Kernel-side memory map summary (what RSS is actually made of).
cat /proc/"$PID"/smaps_rollup > smaps.txt 2>&1 || echo "smaps_rollup not available (needs Linux 4.14+)."
# GC log: cannot be captured retroactively — unified logging must be on from startup.
# Add -Xlog:gc*:file=gc.log to the JVM flags, restart, let it run under load,
# then paste gc.log at https://jvm.expert/gclog
tar czf jvm-diagnostics.tgz nmt.txt histogram.txt threads.txt smaps.txt 2>/dev/null || echo "tar failed — grab the .txt files individually."
echo "Done: jvm-diagnostics.tgz — paste each file at:"
echo " nmt.txt -> https://jvm.expert/nmt"
echo " histogram.txt -> https://jvm.expert/histogram"
echo " threads.txt -> https://jvm.expert/threads"
echo " smaps.txt -> https://jvm.expert/smaps"
Produces nmt.txt, histogram.txt, threads.txt, smaps.txt bundled as jvm-diagnostics.tgz.