2008-07-25

Using WLST to perform regular threaddumps

For that article, I assume that you are already familiar with WebLogic Scripting Tool.

If not, you may have a look here, you will find a description of this project and some useful links (about using WLST offline and online).

Well, here's a little script I wrote for a client to be able to perform threaddumps automatically, without any manual input such as a 'kill -3" or "CTRL+Pause".

Here we go :

serverName = 'AdminServer'
counter = 0
sleepTime = 5000

connect ('weblogic','weblogic','t3://localhost:7001')

for counter in range(10):
java.lang.Thread.sleep(sleepTime)
fileName = 'dump' + serverName + '_' + (java.util.Calendar.getInstance().getTimeInMillis()).toString() + '.dmp'
threadDump('true', fileName, serverName)

Just save the code above in a file, let's say "getThreadDumps.py" and then launch it like :

java weblogic.WLST getThreadDumps.py

or while online : execfile('getThreadDump.py')

6 comments:

Unknown said...

Require WebLogic Server Version >= 9.x

Maxence Button said...

It's true that I should have precised the version of Weblogic you can use WLST with. Actually, it's embedded with WLS 9 and above but you may still use it with WLS 8. More details on the project homepage.

Anonymous said...

Is it possible to modify this to take a thread dump of another managed server? Even when changing serverName to 'myserver', it still seems to take a dump of the AdminServer?

serverName='myserver'
counter=0
sleepTime=5000
connect ('weblogic','weblogic','t3://localhost:7001')
for counter in range(10):
java.lang.Thread.sleep(sleepTime)
fileName = 'dump' + serverName + '_' + (java.util.Calendar.getInstance().getTimeInMillis()).toString() + '.dmp'
threadDump('true', fileName, serverName)

Thanks.

Maxence Button said...

Of course !

The name you define in the var "serverName" is only here to help find your dumps.
If you want to dump a managed server, you simply have to change the port in the "t3://[machine]:[port]" url.

Regards.

Andy said...

Exceptionnel! Merci très beaucoup!

Anonymous said...

Where does the saved script need to be placed? Sorry, I haven't used WLST before. I do get logged in but then get a syntax error and not sure what directory the WLST defaults to 'serverConfig'

SyntaxError: invalid syntax
wls:/SIT11/serverConfig> java weblogic.WLST c:/temp/thread_dump_script.py
Traceback (innermost last):
(no code object) at line 0
File "", line 1
java weblogic.WLST c:/temp/thread_dump_script.py
^

Thanks