This post is written considering to send an email alert message to Admin’s which would alert them about the Thread Pool Health State. All of us know if in Weblogic Health State is as WARNING state then it means something is not going correct in the server and we have to check it. Thus this WLST script would surely help all the Weblogic Administrators who are working in Production Environment.
In below script has a properties file in which you can give all the details about the domain as well as time interval and the number of times the ratio has to be checked.
.
Steps to Create an Email Alert for Threads Pool Health
Step1) Create a Directory somewhere in your file system like : “C:WLST”
Step2) Write a Properties file “domains.properties” inside “C:WLST” like following:
admin.url=t3://localhost:8001 admin.username=weblogic admin.password=weblogic # Number of times the RATIO has to be checked checkTimes_Number=25 # TIME INTERVAL between number of times the RATIO has to be checked (30000 milliseconds = 30 seconds) checkInterval_in_Milliseconds=30000 ############ Accouding to the above values the checker will run for total 25 times in an interval of 30 seconds each. #############
Step-3) Create a WLST Script somewhere in your file system with some name like “Alert_ThreadPoolHealth.py” inside “C:WLST” contents will be something like following:
############################################################################# # # @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved. # ############################################################################# from java.io import FileInputStream import java.lang import os import string propInputStream = FileInputStream("domains.properties") configProps = Properties() configProps.load(propInputStream) serverurl = configProps.get("server.url") adminUser = configProps.get("admin.username") adminPassword = configProps.get("admin.password") checkTimes_Number = configProps.get("checkTimes_Number") checkInterval_in_Milliseconds = configProps.get("checkInterval_in_Milliseconds") i = 0 y = int(checkTimes_Number) ############# This method would send the Alert Email ################# def sendMailString(): os.system('/bin/mailx -s "ALERT: Thread Pool Health is in WARNING !!! " ABCD@COMPANY.com < rw_file') print '********* ALERT MAIL HAS BEEN SENT ***********' print '' ############# This method is checking the Thread Pool Health ################# def alertThreadPoolHealth(healthState): state ="Checking HealthState: " + healthState check = string.find(state,"HEALTH_WARN") if check != -1: print '!!!! ALERT !!!! Thread Pool Health is in WARNING State' print '' message = 'Please Check the Thread Pool is in WARNING State.' cmd = "echo " + message +" > rw_file" os.system(cmd) sendMailString() else: print 'Everything is working fine till now' connect(adminUser,adminPassword,serverurl) serverRuntime() cd('ThreadPoolRuntime/ThreadPoolRuntime') while (i < y): ls() healthState=cmo.getHealthState(); alertThreadPoolHealth(str(healthState)); Thread.sleep(int(checkInterval_in_Milliseconds)) i = i + 1
Step-4) Open a command prompt and then run the “setWLSEnv.cmd” or “setWLSEnv.sh” to set the CLASSPATH and PATH variables. Better you do echo %CLASSPATH% or echo $CLASSPATH to see whether the CLASSPATH is set properly or not. If you see an Empty Classpath even after running the “setWLSEnv.sh” then please refer to the Note mentioned at Step3) in the Following post: http://middlewaremagic.com/weblogic/?page_id=1492
Step-5) Now run the WLST Script in the same command prompt like following:
java weblogic.WLST Alert_ThreadPoolHealth.py
You will see the following kind of results in the command prompt
java weblogic.WLST Alert_ThreadPoolHealth.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands Connecting to t3://localhost:8001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_8001'. Warning: An insecure protocol was used to connect to the server. To ensure on-the-wire security, the SSL port or Admin port should be used instead. Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root. For more help, use help(serverRuntime) -r-- CompletedRequestCount 3714 -r-- ExecuteThreadIdleCount 0 -r-- ExecuteThreadTotalCount 6 -r-- ExecuteThreads weblogic.work.ExecuteThreadRuntime[weblogic.work.ExecuteThreadRuntime@39c4e135, weblogic.work.ExecuteThreadRuntime@2c9d7c34, weblogic.work.ExecuteThreadRuntime@174550ce, weblogic.work.ExecuteThreadRuntime@47bc1051, weblogic.work.ExecuteThreadRuntime@bd35aa2, weblogic.work.ExecuteThreadRuntime@60e347be] -r-- HealthState Component:threadpool,State:HEALTH_WARN,MBean:ThreadPoolRuntime,ReasonCode:[ThreadPool has stuck threads] -r-- HoggingThreadCount 2 -r-- MinThreadsConstraintsCompleted 94 -r-- MinThreadsConstraintsPending 0 -r-- Name ThreadPoolRuntime -r-- PendingUserRequestCount 0 -r-- QueueLength 0 -r-- SharedCapacityForWorkManagers 65536 -r-- StandbyThreadCount 3 -r-- Suspended false -r-- Throughput 9.495252373813093 -r-- Type ThreadPoolRuntime -r-x preDeregister Void : !!!! ALERT !!!! Thread Pool Health is in WARNING State ********* ALERT MAIL HAS BEEN SENT ***********
NOTE: This script is using mailx (i.e. but Windows box does not have mailx utility) so please do check if your mailx is configured properly or else script would run properly but the mail would not be sent.
Regards,
Ravish Mody
April 7th, 2011 on 10:39 am
Hi Ravish,
Would like to understand Thread pool concept for 10.3,with a intension of creating work Manager if required .As I am seeing Stuck Thread issues repeatedly.
Please suggest.
Thanks
Sathya
April 7th, 2011 on 10:43 pm
Hi Sathya,
Cause of Stuck threads can be of many reasons like a dead lock, full GC taking lot of time, SQL query might be taking lot of time etc hence we have to narrow down the issue to what is causing the stuck threads. Thus we have created a WLST script which would take thread dumps during the issue occurred and would send it in your mail so that you would have the thread dump during the issue occurred and you can open a case with the support team to analyse them. Check out the below link
Topic: Sending Email Alert For Stuck Threads With Thread Dumps
http://middlewaremagic.com/weblogic/?p=5582
And about the workmanager below link would give you good idea about it
Topic: WorkManagers
http://middlewaremagic.com/weblogic/?page_id=87
May 23rd, 2011 on 7:01 am
Hi Ravish,
thank you for your script. i have this running in my prod environment. Actually i have one more requirement to copy or move the GC file to a different directory whenever the email is send out.
I run your wlst script as shell script using crontab. is this something you can help?
June 24th, 2011 on 10:52 pm
HI Ravish,
I get this error when i run the script… Any inputs?
Problem invoking WLST – Traceback (innermost last):
File “/d/ct0/home/shahs06/WLST/Alert_ThreadPoolHealth.py”, line 6, in ?
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:120)
at java.io.FileInputStream.(FileInputStream.java:79)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
java.io.FileNotFoundException: java.io.FileNotFoundException: domains.properties (No such file or directory)
June 24th, 2011 on 11:29 pm
Hi Siddhans,
The following Reply will give you some idea. http://middlewaremagic.com/weblogic/?p=6678#comment-4337
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 21st, 2011 on 3:01 pm
hi middleware team,
getting the below error,please help
$ java weblogic.WLST Alert_ThreadPoolHealth.py
Initializing WebLogic Scripting Tool (WLST) …
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Problem invoking WLST – Traceback (innermost last):
(no code object) at line 0
File “/opt/monitoring/cmn_health/Alert_ThreadPoolHealth.py”, line 2
m java.io import FileInputStream
^
SyntaxError: invalid syntax
Regards
Fabian
December 21st, 2011 on 3:21 pm
Hi Fabian,
In the following exception the word “from” is not complete:
File “/opt/monitoring/cmn_health/Alert_ThreadPoolHealth.py”, line 2
m java.io import FileInputStream
So do you have the correct line in your script: as following:
from java.io import FileInputStream
NOT the below one
m java.io import FileInputStream
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
February 7th, 2013 on 7:06 pm
Does this script check all managed servers that are a part of the weblogic domain you are running it against?
February 9th, 2013 on 12:55 am
I found a small issue with this script. took me a while to figure out what the problem was as i kept getting a connection error message
in the domain.properties file you have:
admin.url=t3://localhost:8001
but in the script you have:
serverurl = configProps.get(“server.url”)
the script needs to change to (“admin.url”) to work properly.