This post is written considering to send an email alert message to Admin’s which would alert them about the hogger threads. Hogging threads can be called as a candidates for stuck threads in other words, those threads that “might” get stuck are called hogging threads. These threads will be declared as stuck threads after “StuckThreadMaxTimeout” seconds which by default value is 600secs.
Steps to Create an Email Alert for Hogger Threads Count
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:7001 admin.username=weblogic admin.password=weblogic # This ExecuteThread_Vs_HoggerThreadRatio represtents the division of ExecuteThread/HoggerThreadRatio ExecuteThread_Vs_HoggerThreadRatio=2 # 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_HoggerThreadCoung.py” inside “C:WLST” contents will be something like following:
UPDATED [26-04-2011]: This script has been updated based on the comment — > http://middlewaremagic.com/weblogic/?p=5423#comment-3760, thanks to sathya.
############################################################################# # # @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved. # ############################################################################# from java.io import FileInputStream import java.lang import os propInputStream = FileInputStream("domains.properties") configProps = Properties() configProps.load(propInputStream) adminUrl = configProps.get("admin.url") adminUser = configProps.get("admin.username") adminPassword = configProps.get("admin.password") executeThread_Vs_HoggerThreadRatio = configProps.get("ExecuteThread_Vs_HoggerThreadRatio") 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: Hogger Thread Count Exceeded the Limt !!! " abcd@company.com < rw_file') print '********* ALERT MAIL HAS BEEN SENT ***********' print '' ############# This method is checking the Hogger Threads Ratio ################# def alertHoggerThreads(executeTTC , hoggerTC): print 'Execute Threads : ', executeTTC print 'Hogger Thread Count : ', hoggerTC if hoggerTC != 0: ratio=(executeTTC/hoggerTC) print 'Ratio : ' , ratio print '' if (int(ratio) <= int(executeThread_Vs_HoggerThreadRatio)): print ' !!!! ALERT !!!! Stuck Threads are on its way.....' print '' message = 'ExecuteThreads Count= ' + str(executeTTC) + ' HoggingThreads= '+ str(hoggerTC) +' ExecuteThreads/HoggingThreads Ratio= '+ str(ratio) cmd = "echo " + message +" > rw_file" os.system(cmd) sendMailString() else: print '++++++++++++++++++++++++++++++++++++' print 'Everything is working fine till now' print '++++++++++++++++++++++++++++++++++++' else: print '++++++++++++++++++++++++++++++++++++' print 'Everything is working fine till now' print '++++++++++++++++++++++++++++++++++++' connect(adminUser,adminPassword,adminUrl) serverRuntime() cd('ThreadPoolRuntime/ThreadPoolRuntime') while (i < y): ls() executeTTC=cmo.getExecuteThreadTotalCount(); hoggerTC=cmo.getHoggingThreadCount(); alertHoggerThreads(executeTTC , hoggerTC) print 'Sleeping for ', int(checkInterval_in_Milliseconds) , ' ...' print '' 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 using the following command:
java weblogic.WLST Alert_HoggerThreadCoung.py
You will see the following kind of results in the command prompt
Initializing WebLogic Scripting Tool (WLST) ... ]$ java weblogic.WLST Alert_HoggerThreadCoung.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands Connecting to t3://localhost:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_7001'. 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 2606 -r-- ExecuteThreadIdleCount 1 -r-- ExecuteThreadTotalCount 6 -r-- ExecuteThreads weblogic.work.ExecuteThreadRuntime[weblogic.work.ExecuteThreadRuntime@78de59f8, weblogic.work.ExecuteThreadRuntime@4de4e6c6, weblogic.work.ExecuteThreadRuntime@6eeaf91d, weblogic.work.ExecuteThreadRuntime@48917cf, weblogic.work.ExecuteThreadRuntime@447a195c, weblogic.work.ExecuteThreadRuntime@2c170a23] -r-- HealthState Component:threadpool,State:HEALTH_OK,MBean:ThreadPoolRuntime,ReasonCode:[] -r-- HoggingThreadCount 0 -r-- MinThreadsConstraintsCompleted 104 -r-- MinThreadsConstraintsPending 0 -r-- Name ThreadPoolRuntime -r-- PendingUserRequestCount 0 -r-- QueueLength 0 -r-- SharedCapacityForWorkManagers 65536 -r-- StandbyThreadCount 4 -r-- Suspended false -r-- Throughput 5.0 -r-- Type ThreadPoolRuntime -r-x preDeregister Void : Execute Threads : 6 Hogger Thread Count : 0 ++++++++++++++++++++++++++++++++++++ Everything is working fine till now ++++++++++++++++++++++++++++++++++++ Sleeping for 30000 ...
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 26th, 2011 on 10:17 am
Hi Ravish,
In the above Code, If “Hogger Thread Count” is ZERO, we will get a Exception,
Can we please add if statement there if(hoggerTC > 0)
Thanks
Sathya
April 26th, 2011 on 11:13 am
Hi Sathya,
Yes, you are right. You found a bug in our script which helped us to improve our script. Hence we are happy to give you additional 20 Magic Points to you.
The script is been fixed, so you can now use the latest version of it 😉
Keep Posting 🙂
Regards,
Ravish Mody
April 26th, 2011 on 10:39 am
Hi Ravish,
Here as well instead of specifying the username and password can we have it encrypted, Similar to the post.
http://middlewaremagic.com/weblogic/?p=6186
using storeuserconfig..
Thanks
Sathya
April 26th, 2011 on 10:45 am
Hi Sathya,
This is matter of testing …. 🙂
.
.
Thanks
Jay SenSharma
April 26th, 2011 on 10:59 am
I did try the below
#connect(adminUser,adminPassword,adminUrl)
connect(userConfigFile=’/home/sp07174/MyUserConfigFile’,userKeyFile=’/home/sp07174/MyUserKeyFile’)
But the t3 Url is getting changed as follows, don’t know the exact reason,
bash-3.2$ /export/opt/emt/2.0/wls/bin/emt -ApplicationName CNETPRE -Action ExecutePyScript -ScriptName /home/sp07174/HoggerThreadMonitor.py
Connecting to t3s://cgnrapp1d.nam.nsroot.net:31071 with userid CNETPREAdmin …
Successfully connected to Admin Server ‘CNETPREServer’ that belongs to domain ‘CNETPREDomain’.
Connecting to t3://localhost:7001 with userid CNETPREAdmin …
org.python.proxies.main$WLSTException$4
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)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.python.core.PyInstance.makeProxy(PyInstance.java:82)
Thansk
Sathya
April 26th, 2011 on 11:28 am
Hi Sathya,
You can use storeUserConfig to create an encrypted password userconfig and key file which can then be used in the WLST script something as shown below.
Example:
#To create the user configuration file and key file:
connect(‘weblogic’, ‘weblogic’, ‘localhost:7001’)
storeUserConfig(‘c:/myFiles/myuserconfigfile.secure’,’c:/myFiles/myuserkeyfile.secure’)
#To use the user configuration file and key file:
connect(userConfigFile=’c:/myfiles/myuserconfigfile.secure’,userKeyFile=’c:/myfiles/myuserkeyfile.secure’,url=’t3://localhost:7001′)
Try giving the “url” in the connect command where you want to connect it then run it again.
Regards,
Ravish Mody
April 26th, 2011 on 11:42 am
Hi Ravish,
Adding the URL fixed it..
Thanks
Sathya
November 11th, 2011 on 3:35 pm
Hi,
I want to know threads used by each application in the domain. Is there any way I can get threads per application so find the application which is problematic…?
Thanks,
Kapil.
March 6th, 2012 on 10:52 am
Hi Ravish,
What is the ideal value of executeThread_Vs_HoggerThreadRatio?
If there is no ideal value then how can I determine this value for a server?
Thanks,
Sanjay
March 6th, 2012 on 11:03 am
Hi Sanjay,
What is the ideal value of executeThread_Vs_HoggerThreadRatio?
There is no ideal value for executeThread_Vs_HoggerThreadRati, it totally dependence on your requirement and environment.
If there is no ideal value then how can I determine this value for a server?
This script was written for the percussion of getting stuck threads, hence you can increase or decrease the value as per your convince.
Regards,
Ravish Mody
March 16th, 2012 on 5:25 am
Hi,
Thanks in advance….
I am interested in finding the Hogging threads information not the count “smiler to weblogic console – Tuning Thread Pool Threads ” which thread had stuck or Hogger. I can take thread dump but i am looking for a WSLD command or is there any other way to find it.
Sorry i am new to Weblogic if my Q look stupid please guide me
March 22nd, 2012 on 10:50 pm
How to configure muiltiple servers which are part of cluster and distributed across multiple machines?
March 25th, 2012 on 3:33 pm
Hi Jai,
You can try the steps given in the below article
Topic: WebLogic Clustering in Remote Boxes
http://middlewaremagic.com/weblogic/?p=971
September 25th, 2015 on 6:10 pm
Hi Ravish,
Do you know why the another script for mailing stuck threads was no available?
September 26th, 2015 on 6:01 am
Hello Goku,
It’s available now: http://middlewaremagic.com/weblogic/?p=5423
Due to some maintenance activity it was unavailable for some time.
Regards
Jay SenSharma