Skip to content

Instantly share code, notes, and snippets.

@andy012
Created November 17, 2016 03:54
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 andy012/2e8b92ac890731a502cbccfd8e6a9c59 to your computer and use it in GitHub Desktop.
Save andy012/2e8b92ac890731a502cbccfd8e6a9c59 to your computer and use it in GitHub Desktop.
get jvm heap usage with shell
#!/bin/bash
pidVal=$( ps -ef | grep "/data/www/tomcat-unifymonitor/conf/logging.properties -" | grep -v grep | awk -F' ' '{print $2}' | tr "\n" "," | cut -d ',' -f1 )
capacityLine=$(/usr/java/jdk1.7.0_65/bin/jstat -gccapacity ${pidVal} | tail -n 1 )
percentageLine=$(/usr/java/jdk1.7.0_65/bin/jstat -gcutil ${pidVal} | tail -n 1)
memValReal=`gawk -v v1="$capacityLine" -v v2="$percentageLine" 'BEGIN{
split(v1,cArray," ");
split(v2,pArray," ");
sum=0.0;
# S0C Current Usage = S0C*S0/100.0
sum=sum + (cArray[4]*pArray[1]/100.0);
# S1C Current Usage = S1C*S1/100.0
sum=sum + (cArray[5]*pArray[2]/100.0);
# Eden Current Usage = EC*E/100.0
sum=sum + (cArray[6]*pArray[3]/100.0);
# Old Current Usage = OC*O/100.0
sum=sum + (cArray[9]*pArray[4]/100.0);
sum=sum/1000000;
printf "%.2f\n",sum;
}'`
echo $memValReal
standardVal=3.0
if [ $(echo "$memValReal > $standardVal" | bc) -eq 1 ];then
echo $memValReal
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment