Script to generate Heapdump in WAS

#!/bin/sh

echo “INFO: This script will generate heapdump and threaddumps.”
echo “INFO: Checking if the the WAS process is running.”

DATE=`date +%Y%m%d`
processDetail=`ps -ef|grep $USER|grep java|grep -v  grep|awk ‘{print $1,$2}’`;
pid=`ps -ef|grep $USER|grep java|grep -v  grep|awk ‘{print $2}’`
diskUsage=`df -hl|grep “/$USER”|grep -o [0-9]*%|grep -o [0-9]*`

if `echo $processDetail | grep “$USER [0-9]*” 1>/dev/null 2>&1`
then
echo “INFO: WAS process is running.”
else
echo “ERROR: WAS not running, cannot generate heap/thread dumps.”;
exit 1;
fi

if [[ $diskUsage -gt 90 ]]
then
echo “ERROR: Disk usage for profile filesystem is greater than 90%, not enough space.”
exit 1;
else
echo “INFO: Adequate disk space available, proceeding with heap / thread dump generation.”
if [[ -f ~/generateDumps.jy ]]
then
/${USER}/profile/bin/wsadmin.sh -host ${USER} -lang jython -f ~/generateDumps.jy
else
echo “ERROR: Jython file doesnt exist.”
exit 1
fi
fi

#dateStr=`date “+%Y%m%d.%H%M”`
#echo “date: ${dateStr}”
#echo “pid = ${pid}”
#echo “listStr = ${listStr}”
listStr=`echo “/${USER}/profile/*${DATE}*.${PID}.*”`
echo “INFO: The newly generated files are listed below: ” $listStr

Below is the jython script:
#Generates heapdump and threadump at defualt location.
# in most cases that would be /<VAH>/profile/
# VV

import re

ServerJVM = AdminControl.completeObjectName(‘type=JVM,process=server1,*’)

if ServerJVM==”:
print “ERROR: Something went wrong – try again later!”
else:
threadump = AdminControl.invoke(ServerJVM,’dumpThreads’)
heapdump = AdminControl.invoke(ServerJVM,’generateHeapDump’)

if threadump == ”:
print “INFO: Threaddump generated”
else:
print “ERROR: Unable to generate threadump!!”
print “ERROR: Reason:” + threadump

if re.search(‘heapdump.*phd’, heapdump):
print “INFO: Heapdump generated successfully at: ” + heapdump
else:
print “ERROR: Unable to generate heapdump…”
print “ERROR: Reason: ” + heapdump

 

Advertisements