There are scenarios when you would want to monitor the properties of your alive servers in the Domain using the WebLogic Server Runtime Mbeans. Properties like Server State, Server Health, Listen Port, Listen Addresses etc.
This can be achieved through many ways like the Admin Console, JMX code, WLST scripts etc. WLST allows us to automate the monitoring.
WebLogic Server runtime MBeans are arranged in a hierarchical data structure. When connected to an Administration Server, you access the runtime MBean hierarchy by entering the
serverRuntime
or thedomainRuntime
command. TheserverRuntime
command places WLST at the root of the server runtime management objects,ServerRuntimeMBean
; thedomainRuntime
command, at the root of the domain-wide runtime management objects,DomainRuntimeMBean
. When connected to a Managed Server, the root of the runtime MBeans isServerRuntimeMBean
. The domain runtime MBean hierarchy exists on the Administration Server only; you cannot use thedomainRuntime
command when connected to a Managed Server.
The below post depicts the usage of WLST to monitor the Server State of all the running servers in the domain.
Steps:
1. Script to monitor Server Runtime States
a. Save the below script ServerStatus.py on to your local machine.
**************************************************************************
username = 'weblogic' password = 'weblogic' URL='t3://localhost:8001' connect(username,password,URL) domainRuntime() cd('ServerRuntimes') servers=domainRuntimeService.getServerRuntimes() for server in servers: serverName=server.getName(); print '**************************************************n' print '############## ', serverName, '###############' print '**************************************************n' print '##### Server State #####', server.getState() print '##### Server ListenAddress #####', server.getListenAddress() print '##### Server ListenPort #####', server.getListenPort() print '##### Server Health State #####', server.getHealthState()
**************************************************************************
2. Execute the WLST Script
a. Set the CLASSPATH by running the setDomainEnv script from the
Alternatively you can set the CLASSPATH by specifying the –cp argument while executing the WLST Script
For Ex: java –cp $BEA_HOME/wlserver_10.3/server/lib/weblogic.jar weblogic.WLST ServerStatus.py
Downloads
You can download the WLST script from the below link.
Note: Save the script as ServerStatus.py
References:
http://download.oracle.com/docs/cd/E11035_01/wls100/config_scripting/monitoring.html
Regards,
Wonders Team. 🙂
I am getting invalid syntax error for line 9: serverName=server.getName();
Please suggest me..with the correct syntax.
Hi Ashok,
We will mail you the script.
Cheers!
Faisal
I am also facing the same issue, could you send me the script too..
sure Suresh!
Hi Suresh,
I have pasted the download link for the WLST script in the post.
Download and execute the same.
Cheers,
Anandraj
The getHealthState() returns Component:ServerRuntime,State:HEALTH_OK,MBean:ewbsacovn48_e_1,ReasonCode:[] … How can I test to see that HEALTH is OK or in Warning or other condition?
Kindly post your question to our forum
https://weblogic-wonders.com/weblogic/forum/#/
./ServerStatus.py: line 3: username: command not found
./ServerStatus.py: line 5: password: command not found
./ServerStatus.py: line 9: syntax error near unexpected token `username,password,URL’
./ServerStatus.py: line 9: ` connect(username,password,URL)
Hi Naveen,
Try to download the WLST script from the link provided in the article.
https://5vmd6c.p3cdn1.secureserver.net/weblogic/wp-content/uploads/2011/03/ServerStatus.py_1.txt
Regards,
Anandraj
Hi,
A small correction in your above ServerStatus.py script which is downloadable.
print ‘############## ’, serverName, ’###############’
comma & single codes are missing in that .
Thanks
Pawan
Good correction.
Please subscribe me… this site is very useful to us
thanks
lokesh
sure lokesh!
It is a nice to show helath of the running servers – but what about those stopped/crashed?
How can I auto mail for server HEALTH is in Warning or overlaod other condition state?
i need help on health state become warrning and overload i need mail for health status
please send me do you have any scripts
Hi Adi,
Apologies for the late reply.
Am afraid we do not have WLST scripts for the same.
However you can use the WLDF feature to configure the same via admin console. It is fairly simple.
Please refer the below post for the same.
https://weblogic-wonders.com/weblogic/2009/12/01/configuration-wldf-mail-notification-for-runtime-mbean/
Regards,
Anandraj
Hi i have tested this script.. but it comes as State:HEALTH_OK,ReasonCode:[]
in all cesses.. i have observed that my servers have gone to overloaded state but still the script gives the same response. Any suggestions ..
Please let me know if this script can monitor and give status for multiple domains located on a server.
Hi Kalyan,
You will have to customize this script.
Thanks,
Faisal
Problem invoking WLST – Traceback (innermost last):
(no code object) at line 0
File “/oracle/ServerStatus.py”, line 17
serverName=server.getName();
^
SyntaxError: invalid syntax
getting this error while running the script. please suggest.