Skip to content

Instantly share code, notes, and snippets.

@safchain
Last active August 29, 2015 14:07
Show Gist options
  • Save safchain/f86500dfcd97983701df to your computer and use it in GitHub Desktop.
Save safchain/f86500dfcd97983701df to your computer and use it in GitHub Desktop.
Java Memory Usage
#!/bin/sh
if [ -z "$1" ]
then
echo "Usage: $0 <java process name>"
exit 1
fi
PID=`jps | grep $1 | awk '{print \$1}'`
jmap -heap $PID 2>/dev/null > /tmp/jheap
CAPACITY=`grep capacity /tmp/jheap | grep = | awk '{TOTAL += $3} END{print TOTAL}'`
USED=`grep used /tmp/jheap | grep = | awk '{TOTAL += $3} END{print TOTAL}'`
PERCENT=$(( $USED * 100 / $CAPACITY ))
echo total:$CAPACITY used:$USED percent used:$PERCENT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment