Saturday, September 14, 2013

JVM monitoring with jstat

The Oracle WebLogic Server instances are nothing but each one running on single JVM, when this JVM crashes there could be one of the reason as over working of Garbage Collection  or not working at all (waiting continuously).  It is good practice that monitoring GC in JVM with a detailed statistics will give you a clear idea to analysis at what circumstances happening wrong. And 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)

jps 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.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
##############################################################
# 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 |" `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 |    Eden    \t|    Old Gen   \t|    Perm Gen"
echo -e "          |Current Used\t| Current Used \t| Current Used"
echo -e "=============================================================="
  
for i in ` ls $HOME/instances/|grep c`
do
        PID=`$JAVA_HOME/bin/jps -lv | grep $i | awk '{print $1}'`
        if [ "$PID" != ""  ]
        then   
                instJvm $PID $i
        fi     
done
echo -e "=============================================================="

Taking Advantage of Naming Conventions


In most of the Middleware environments, the WebLogic domain  will have admin servers, managed servers uses naming convention construct that will have some common identity for each domain unique. In the above the example, The domain uses naming convention with letter 'c', This can be any word or letter that is used in your environments. 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:
?
1
2
3
4
5
6
7
8
9
10
====================================================
 Instance |    Eden     |    Old Gen    |    Perm Gen
          |Current Used | Current Used  | Current Used
====================================================
cadmin     | 426M   242M   | 512M   185M   | 256M   245M
cmserver10 | 426M   158M  | 512M   292M   | 152M   113M
cmserver11 | 426M   73M   | 512M   251M   | 152M   113M
cmserver12 | 426M   311M  | 512M   291M   | 152M   113M
cmserver13 | 426M   185M  | 512M   342M   | 152M   113M
====================================================

Looking ahead for your valuable comments and suggestions to improve our scripting tricks for better WebLogic Administration.

jstat Command reference:
http://roundoverlinux.blogspot.in/2013/03/jstat-command-is-java-virtual-machine.html

No comments:

Post a Comment