Last year, we were struggling to overcome the OutOfMemoryError, which would effect the most of productive hours. In this assignment I need to figure out what process is causing the low memory in the environment is identified by searching a all log files in the machine. Assume that all the WebLogic instance log files are collected into common directory structure, each of them are stored respective instance named folder.
Script 1:
After identifying the impacted instances, I need to take the heap dump of that particular instance with corresponding process id.
#============================================================== # File Name : CheckLogs.sh # Author : Pavan Devarakonda # Purpose : Script for searching all WebLogic instances logs in a box #============================================================== instances=`ls /path/instances|grep web` phrase=$1 date for x in $instances do echo 'Checking in the :' $x cd /path/instances/$x/logs egrep -i $phrase instance*log egrep -i $phrase instance*out done # Know the CPU load average at this time date uptime-->
Script 2: Automatic script for Heap dump, here you need to provide the managed server name at the command-line argument.
#!/bin/bash #======================================================= # Name : InstanceHeapdump.sh # Purpose : This script will takes instance name as input # Takes the thread dump and also takes heap dump #======================================================= if [ "$1" = "" ]; then echo "Usage : $0" exit else instance="$1" user=$LOGNAME ppid=`ps -fu $user|grep $instance|grep startMan|grep -v grep|awk '{print $2}'` wpid=`ps -fu $user|grep $ppid|grep startWebLogic.sh|awk '{print $2}'` jpid=`ps -fu $user|grep $wpid|grep java|awk '{print $2}'` echo 'The Java PID:' $jpid kill -3 $jpid if [ $jpid = "" ]; then echo "Invalid instance input..." exit else jmap -dump:live,format=b,file=heap.bin $jpid mv heap.bin $instance_heap.bin fi fi
This could give you one more way of finding a java process in UNIX machine. You can use jps command instead of three lines of awk filters. In this same script to make hold the java process not to crash, we can call a WLST script to suspend the instance and then you can happily take the heap dump.
What to do after heapdump creation?
Use jhat command to run the analyzer to show the outcome on a browser.
Follow the Faisal tips to find memory leaks, use eclipse MAT that is comfortable for your system.