The first step is to establish a connection to the Admin Server. From there, the script will perform the threadDump() function in a particular server. The number of thread dumps to take can be defined and the sleep time between them as well.

Every thread dumps will be saved as a file with the following name structure "dump_<server name>_<thread dump time>.dmp" in the same directory where the script was launched. After that, the connection with the Admin Server will be closed.

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

Linux version



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

from time import strftime
from java.text import SimpleDateFormat
serverName = 'MS1'
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 version

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()

Run the script as follow: java weblogic.WLST ThreadDumps.py

0 Comments