It is good practice that monitoring GC in JVM with detailed statistics will give you a clear idea to analysis at what circumstances happening wrong. And the best way to look in deeper levels of garbage collection also like Young Generation (Eden space, Survivor spaces S0, S1) Old Generation (tenured Generation), and Perm Generation (Statistic Objects/Classes).
JDK 1.5 and latest providing excellent JDK command utilities for interrogate the current running Java Process and look inside of JVM take snap with following:
1. jps (Java Process)
2. jstat (JVM status)
The 'jps' command with -lv options gives you complete detailed java process arguments for MEM settings and relavent WebLogic Server instances name. We have already discussed about this command utility in another post.
The jstat command with -gc option will produce the Garbage Collection of given java process id.
In most of the Middleware environments, the WebLogic domain will have admin servers, managed servers use naming convention construct that will have some common identity for each domain unique. In the above example, The domain uses naming convention with the letter 'c', This can be any word or letter that is used in your environment. To make your script you need to replace 'c' with your enviroment key word/letter. (Thanks Raman Jain for your valuable comment)
Let me show you the sample Output:
The jstat Command reference:
JDK 1.5 and latest providing excellent JDK command utilities for interrogate the current running Java Process and look inside of JVM take snap with following:
1. jps (Java Process)
2. jstat (JVM status)
The 'jps' command with -lv options gives you complete detailed java process arguments for MEM settings and relavent WebLogic Server instances name. We have already discussed about this command utility in another post.
The jstat command with -gc option will produce the Garbage Collection of given java process id.
GC Monitoring shell script with jstat tool
I have modified according to my convenience and requirements as a shell script that will take the argument as WebLogic Server instance name and give us the output as statistics of Young, Old, Perm Generations Current, Used Memory details in MB conversion function.############################################################## # Purpose: To display current, used spaces for an instance # in the JVM Eden, Old, Perm sizes # Author: Pavan Devarakonda ############################################################## # Function for converting the Kilo bytes to Mega Bytes. toMb() { echo 'scale=0;'$1'/1024' | bc; } #============================================= # JVM status Function starts here #============================================= instJvm() { DATA=`$JAVA_HOME/bin/jstat -gc $PID | grep -v S0C` EC=`echo $DATA | awk '{print $5}'` EU=`echo $DATA | awk '{print $6}'` OC=`echo $DATA | awk '{print $7}'` OU=`echo $DATA | awk '{print $8}'` PC=`echo $DATA | awk '{print $9}'` PU=`echo $DATA | awk '{print $10}'` echo -e "$2\t|" `toMb $EC`"M "`toMb $EU`"M\t| "`toMb $OC`"M "`toMb $OU`"M\t| "`toMb $PC`"M "`toMb $PU`"M" } #============================================= # main starts here #============================================= echo -e "==============================================================" echo -e " Instance\t | Eden \t| Old Gen \t| Perm Gen" echo -e " \t |Current Used\t| Current Used \t| Current Used" echo -e "==============================================================" DOMAIN_HOME=$1 for i in ` ls $DOMAIN_HOME/servers/|grep -v bkp` do PID=`$JAVA_HOME/bin/jps -lv | grep $i | awk '{print $1}'` if [ "$PID" != "" ] then instJvm $PID $i fi done echo -e "=============================================================="Example execution:
./jstat_mon.sh /u01/domains/apex_domainThe output as follows:
The jstat command using script |
Taking Advantage of Naming Conventions
In most of the Middleware environments, the WebLogic domain will have admin servers, managed servers use naming convention construct that will have some common identity for each domain unique. In the above example, The domain uses naming convention with the letter 'c', This can be any word or letter that is used in your environment. To make your script you need to replace 'c' with your enviroment key word/letter. (Thanks Raman Jain for your valuable comment)
Let me show you the sample Output:
Looking ahead to your valuable comments and suggestions to improve our scripting tricks for better WebLogic Administration.
The jstat Command reference:
Hi Pawan
ReplyDeletewhat are you trying to extract out of this statement:-
for i in ` ls $HOME/instances/|grep c`
I did not had this directory so I created one , but I could not understand what will be grapped out of it as there is nothing in it.
Can you please provide some inputs.
Thanks for this article. it is really useful.
got that...it is the weblogic instance names....perfect its done. thanks
ReplyDeletethanks for this amazing blog , keep posting and checkout my blog full stack java classes in pune
ReplyDelete