Basic Shell Script to Monitor JVM Heap Usage of Weblogic Managed Servers

Basic Shell Script to Monitor JVM Heap Usage of Weblogic Managed Servers

Below is the basic shell scripting which will monitor JVM heap usage of admin server and managed server and will send a alert mail if heap used is more than 85 %. Here 85% is threshold value of total heap allocated to managed server. You can change accordingly as per your environment. In this script weblogic commad line utility weblogic.admin is used. You can shcedule a cronjob for frequent monitoring depending on the environment. ————————————————————————————————-
set -x
export CLASSPATH=”/wl_home/server/lib/weblogic.jar”
declare -a Port=( 8003 7072 8201 )
declare -a HeapFreeCurrent[]
declare -a HeapSizeCurrent[]
declare -a ServerName[]
declare -a ObjectName[]
i=”0″
while [ $i -lt 5 ]
do
HeapFreeCurrent[$i]=`java weblogic.Admin -url 10.17.19.200:${Port[$i]} -username weblogic -password weblogic GET -pretty -type JVMRuntime -property HeapFreeCurrent |grep -i HeapFreeCurrent |awk ‘{print $2}’`
HeapSizeCurrent[$i]=`java weblogic.Admin -url 10.17.19.200:${Port[$i]} -username weblogic -password weblogic GET -pretty -type JVMRuntime -property HeapSizeCurrent |grep -i HeapSizeCurrent |awk ‘{print $2}’`
ObjectName[$i]=`java weblogic.Admin -url 10.17.19.200:${Port[$i]} -username weblogic -password weblogic GET -pretty -type JVMRuntime -property ObjectName |grep -i ObjectName |awk ‘{print $2}’`
g=${HeapSizeCurrent[$i]}/1000000
JVMTHRESHOLD=$(($g*85/100))

USEDJVM=`expr ${HeapSizeCurrent[$i]} – ${HeapFreeCurrent[$i]}`
m=$(($USEDJVM*1/1000000))
x=$((${HeapSizeCurrent[$i]}*1/1000000))
y=$((${HeapFreeCurrent[$i]}*1/1000000))
if [ $m -gt $JVMTHRESHOLD ] ; then
mailx -s ” Weblogic Java Heap Alert – 10.17.19.200 ” kartheek@solaris.com<
JVM Utilization is $m MB on weblogic managed server ${ObjectName[$i]}.                                                            
${ObjectName[$i]} is being utilized above threshold – 85% of $x MB                                                     
“Current heap size allcated to ${ObjectName[$i]}:” $x MB                                                            
“Available heap size on ${ObjectName[$i]}:” $y MB                                                                
EOF
fi
i=`expr $i + 1`
done
————————————————————————————————–