Skip to content

Instantly share code, notes, and snippets.

@henrikno
Created April 30, 2020 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrikno/4eabd7a4cb5be2f37f9d86145e5cae39 to your computer and use it in GitHub Desktop.
Save henrikno/4eabd7a4cb5be2f37f9d86145e5cae39 to your computer and use it in GitHub Desktop.
Get current/max memory usage for java process
PID=$(jps | grep Main | awk '{print $1}')
CUR=$(jstat -gc $PID | tail -n 1 | awk '{split($0,a," "); sum=a[3]+a[4]+a[6]+a[8]; print sum/1024}')
MAX=$(jstat -gccapacity $PID | tail -n 1 | awk '{split($0,a," "); sum=a[2]+a[8]; print sum/1024}')
echo $CUR/$MAX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment