Tuesday, December 4, 2012

How to take Thread dump in Weblogic(linux/windows) using the WLST script



Action Plan

1. Save the content of the script as "ThreadDumps.py".
2. Modify the script as follows:
2.1 Specify the server name that you are going to monitor (serverName).
2.2 Specify the number of quantity of thread dumps to take (threadNumber).
2.3 Specify the parameters for the connection string: username, password, hostname and port of the Admin Server.
3. Save the file.
4. Set up the environment for WLST. Check the following documentation: http://download.oracle.com/docs/cd/E11035_01/wls100/config_scripting/using_WLST.html#wp1093943
5. Run the script as follow: java weblogic.WLST ThreadDumps.py
6. As the result of the script, you will get some dmp files that contain the thread dumps.


The following script will take 5 thread dumps on the server "ManagedServer1", 15 seconds apart form each other. 

Linux

*****************************************************************

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

from time import strftime
from java.text import SimpleDateFormat
serverName = 'ManagedServer1'
counter = 0
sleepTime = 15000
threadNumber = 5

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

disconnect() 

****************************************************************

Windows

This particular version of the script introduces some changes in the way how thread dump files are being saved.

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

from java.lang import *
from java.util import Date

serverName = 'MS1'
counter = 0
sleepTime = 15000
threadNumber = 10

d= Date()

for counter in range(threadNumber):
        currentFile = 'Thread_Dump_%s_%s_%s.log' % (serverName, d.time,counter)
        threadDump(writeToFile='true', fileName=currentFile,serverName=serverName)
        currentFileRead = open(currentFile, 'r')
        currentFileRead.close()
        Thread.sleep(sleepTime)

disconnect()
*****************************************************************

1 comment: