Sunday, November 29, 2015

Capture thread dumps on WebLogic server or on Metasolv application servers

At many instances one might notice that the WebLogic/Metasolv servers (Weblogic Admin or Managed servers) are displayed in WARNING state in the admin console, one of the possible reason for the WARNING is stuck threads or JMS bridges not coming up properly or similar such issues.

In such situations it becomes very important to debug(using thread dumps) to find out which application(API)/code is causing these warnings/issues.

Lets look at the ways of capturing the thread dumps.

1. WebLogic console


This is one of very easy way to capture thread dumps but it is not the preferred method due to the limited details of its output.

To capture thread dump please follow below steps.

Login to WebLogic Admin Console —> Servers —> Monitoring —> Threads

Then click Dump Thread Stack.


2.  Command Line or shell


WebLogic 8.1 does not provide a way to invoke a THREAD DUMP using the "Dump Thread Stacks" feature from the WebLogic Administration Console as provided in 10.3.

For Weblogic 8.1 thread dumps can be captured from below command from a command line or shell.

WebLogic command (java weblogic.Admin -url t3://serverhost:serverport -username <USER> -password <PASSWORD> THREAD_DUMP)

NOTE: The weblogic.jar must be in the CLASSPATH to avoid a "java.lang.NoClassDefFoundError: weblogic/Admin" exception (see below).



3. Kill -3 <PID> command


Use the "ps -ef | grep"  or "/usr/ucb/ps auxwwwww|grep"(shows memory parameters too) command
to identify the WebLogic Server's java process ID or <PID>.

Grep argument could be your server name but the <PID> will be the java process ID.

See below for exact steps.


THREAD DUMP data is logged to the ${MSLV_HOME}/${SERVER_NAME}/appserver/logs/${SERVER_NAME}.mss.log file.

4.  Using a WLST script

Below script describes how to take thread dump using WLST.
  1. Establish a connection to the Admin Server.
  2. Provide Server Name where you want to take thread dump i.e. managed server test_srvr_1.1 and provide 5 number(any quantity) of thread dumps and take each dump after 10 secs interval.
  3. Save the file as "ThreadDump.py" at /opt/xyz/abc/Test_domain(choose your location).
  4. Now to execute the above file and go to weblogic server bin directory(as per your directory structure), run cd /opt/xyz/abc/bea/wli10gR3MP1/wlserver_10.3/server/bin.
  5. Run ". ./setWLSEnv.sh" ---to set up class path.
  6. Run "java weblogic.WLST /opt/xyz/abc/Test_domain/ThreadDump.py"
  7. As the result of the script, you will get some dmp files that contain the thread dumps in the same directory where ThreadDump.py is placed.


File: ThreadDump.py

# Purpose: To generate thread dump at specific interval
# Author: Alok Mishra
# Contact: alokmishra188@gmail.com

connect('weblogic','weblogic1','localhost:7001')

from time import strftime
from java.text import SimpleDateFormat
serverName = 'test_srvr_1.1'
counter = 0
sleepTime = 10000
threadNumber = 5

for counter in range(threadNumber):
        currentDate = java.util.Date().toString()
        myDate = currentDate.split(' ');
        finalDate = myDate[3]
        java.lang.Thread.sleep(sleepTime)
        fileName = 'Thread dump' + '_' + serverName + '_' + finalDate + '.dmp'
        threadDump('true', fileName, serverName)

disconnect()


Hope the article helps you in understanding how to take thread dumps, please leave your feedback or query.

No comments:

Post a Comment