Taking Thread Dumps Multiple Times in WebLogic Using Script

Using the following steps, we can generate thread dumps for Weblogic JVM’s:

 

Step 1:

Firstly, if the user is using Java, then the user should export the Java path as “export JAVA_HOME=Java_Installed_Path”

Ex: export JAVA_HOME=/oracle/java/jdk1.7.0_80

 

Step 2:

To export the JVM Process-ID value to PID, users could either use the code “export PID=`ps -ef | grep -i “[D]weblogic\.Name=Weblogic_JVM_Name” or “export PID=` /usr/ucb/ps -auxwww | grep -i “[D]weblogic\.Name=Weblogic_JVM_Name” `

Ex : export PID=` /usr/ucb/ps -auxwww | grep -i “[D]weblogic\.Name=server1″`
export PID=`ps -ef | grep -i “[D]weblogic\.Name=server1″`

 

Step 3:

From there, users can export thread dumps file locations to TD_file by using

export TD_FILE=filepath/threaddump_`date +%Y%m%dT%H%M%S%Z`.out
echo “Thread dump file generation (`date`)” > ${TD_FILE}

Ex: export TD_FILE=/var/tmp/threaddump_`date +%Y%m%dT%H%M%S%Z`.out
echo “Thread dump file generation (`date`)” > ${TD_FILE}

 

Step 4:

For the loop, users should specify the numner dumps and the time pause for each time using sleep parameters by inputting the following code:

for i in {1..N}; do echo “`date +%s.%N` – Thread dump $i”; $JAVA_HOME/bin/jstack -l $PID >> ${TD_FILE} 2>&1; echo “`date +%s.%N` – Done dump $i”; sleep time_in_seconds; done

Ex: for i in {1..10}; do echo “`date +%s.%N` – Thread dump $i”; $JAVA_HOME/bin/jstack -l $PID >> ${TD_FILE} 2>&1; echo “`date +%s.%N` – Done dump $i”; sleep 15; done

 

Step 5: 

Lastly, if the user would like to compress the generated dump files, he or she could use the following code to move the file inside the zip:

zip -9m ${TD_FILE}.zip ${TD_FILE} #

No Comments

Leave a Comment

Your email address will not be published.