While trouble shooting administrator need to check the status of all server instances. This is the basic need when the all the servers are in bounced for production code move. This same script can be applicable for the pre-production or staging environment too. WLST provides the built-in methods, which gives the status of the Server instance or servers in a Cluster. Here we will deal with individual instance wise data.

Using above shown MBean hierarchy we can can fetch the all WebLogic domain server instance's states. If your production WebLogic domain consists of two digit (eg. 60 instances) or three digit number (eg. 120 instances) of managed server then, it is difficult to see all server’s state at once. Weblogic Administration console is unable to show all the servers in the domain on a single page. Navigating in between also a time eating process so think! think better way!! WLST has the solution.
To get the status of all servers in the domain can be obtained with the following steps
1. Connect to the Admin Server
2. Fetch the server list from the domain runtime MBean
3. Iterate the loop and get the state of each managed server with Server Life Cycle Runtime MBean
4. Repeat if required the step 3 as per the user input
5. Finally disconnect
Smart Script
Recently I have discussion with Dianyuan Wang, state of the managed servers can be obtained with state() command. It can be used in two ways: To get individual managed server status you need to pass arguments as managed server name, type as 'Server'. Other one is to get individual Cluster wise status. This can be achieved by passing two arguments cluster name and type as 'Cluster'. The following script will be illustrate the second option. which I found that short code that gives same script outcome as above script. It could be leverage your scripting thoughts it is like a plain vanilla form as shown:
Note: Hope you follow the WLST Tricks & tips
Please write back your experiencing with this posting looking ahead for your comments.

Using above shown MBean hierarchy we can can fetch the all WebLogic domain server instance's states. If your production WebLogic domain consists of two digit (eg. 60 instances) or three digit number (eg. 120 instances) of managed server then, it is difficult to see all server’s state at once. Weblogic Administration console is unable to show all the servers in the domain on a single page. Navigating in between also a time eating process so think! think better way!! WLST has the solution.
To get the status of all servers in the domain can be obtained with the following steps
1. Connect to the Admin Server
2. Fetch the server list from the domain runtime MBean
3. Iterate the loop and get the state of each managed server with Server Life Cycle Runtime MBean
4. Repeat if required the step 3 as per the user input
5. Finally disconnect
##################################################
# This script is used to check the status of all WL instances including the admin
###########################################################
def conn():
UCF='/path/.AdminScripts/userConfigFile.sec'
UKF='/path/.AdminScripts/userKeyFile.sec'
admurl = "t3://hostname:wlport"
try:
connect(userConfigFile=UCF, userKeyFile=UKF, url=admurl)
except ConnectionException,e:
print '\033[1;31m Unable to find admin server...\033[0m'
exit()
def ServrState():
print 'Fetching state of every WebLogic instance'
#Fetch the state of the every WebLogic instance
for name in serverNames:
cd("/ServerLifeCycleRuntimes/" + name.getName())
serverState = cmo.getState()
if serverState == "RUNNING":
print 'Server ' + name.getName() + ' is :\033[1;32m' + serverState + '\033[0m'
elif serverState == "STARTING":
print 'Server ' + name.getName() + ' is :\033[1;33m' + serverState + '\033[0m'
elif serverState == "UNKNOWN":
print 'Server ' + name.getName() + ' is :\033[1;34m' + serverState + '\033[0m'
else:
print 'Server ' + name.getName() + ' is :\033[1;31m' + serverState + '\033[0m'
quit()
def quit():
print '\033[1;35mRe-Run the script HIT any key..\033[0m'
Ans = raw_input("Are you sure Quit from WLST... (y/n)")
if (Ans == 'y'):
disconnect()
stopRedirect()
exit()
else:
ServrState()
if __name__== "main":
redirect('./logs/Server.log', 'false')
conn()
serverNames = cmo.getServers()
domainRuntime()
ServrState()Smart Script
Recently I have discussion with Dianyuan Wang, state of the managed servers can be obtained with state() command. It can be used in two ways: To get individual managed server status you need to pass arguments as managed server name, type as 'Server'. Other one is to get individual Cluster wise status. This can be achieved by passing two arguments cluster name and type as 'Cluster'. The following script will be illustrate the second option. which I found that short code that gives same script outcome as above script. It could be leverage your scripting thoughts it is like a plain vanilla form as shown:
Note: Hope you follow the WLST Tricks & tips
try:
connect(url = "t3://adminhostname:adminport")
except:
print "Connection failed"
state('appclstr','Cluster')
state('web1clstr','Cluster')
state('web1clstr','Cluster')
...
state('webNclstr','Cluster')
Extra Stroke of this new script is that prints how many servers available in each given cluster.Please write back your experiencing with this posting looking ahead for your comments.
20 comments:
Hi Pavan,
Thank you so much for these examples you put online. These are immense help in learning WLST.
I have a quick question: I want to modify the server state monitoring script you have to allow monitoring multiple admin and their managed servers (I have 6 different admin servers with 6 managed servers each. They are not clustered).
I am trying to find out if WLST has the capability of reading from a txt file where I can put the admin server URL, username, pass.
Could you please give me some hints on how I can try to implement this?
use loadProperties instead of file reading.
Hello Pavan,
I have modiefied a bit the script like this:
def ServerConn():
username = 'weblogic'
password = 'wlsfusion01'
url = 't3://muciipd01:7011'
connect(username, password, url)
def ServrState():
print 'Fetching state of every WebLogic instance'
#Fetch the state of the every WebLogic instance
for name in serverNames:
cd("/ServerLifeCycleRuntimes/" + name.getName())
serverState = cmo.getState()
if serverState == "RUNNING":
print 'Server ' + name.getName() + ' is :' + serverState
print 'End of script ...'
when I run it I get:
[oracle11@muciipd01 ~]$ java weblogic.WLST state.py
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
End of script ...
I guess I should explicity define the domainRuntime() in the beginning because I am not sure that after logging the cmo is the domainRuntime().
Thanks in advance.
Loukas
Hey Loukas,
You can run the above script as is by updating your credentials. If you don't want colors in ur output then you can goahead with your way of script, Yes you required domainRuntime tree to fetch the Managed servers state. By default it will be on serverConfig tree when you connect the admin server. Define your module on top it will be easy to access. Remember to use python indentation blocks (4 spaces or a tab) while writing the blocks of code. Hope this will help you.
Please comment if anything missing...
Hey Pavan,
unfortunately I cannot replay the same exact script as your since I have not configured yet sec config files for the credential. But it doesn't matter. Basically i get your script and I am trying to do something very simple but still it doesn't work.
I am writting my script on the Eclipse (Oracle Enterprise Pack for Eclipse (OEPE))
By the way what is the editor you are using and it is shown in the screenshot above? Hiw can I tag my code so that you can see my script with the indentation blocks?
I tried to even more make it more simple like following:
print 'starting the script ....'
def getServerNames():
domainConfig()
return cmo.getServers()
def serverStatus(server):
cd('/ServerLifeCycleRuntimes/' +server)
return cmo.getState()
def printStatus():
print 'Fetching state of every WebLogic instance'
connect('weblogic','welcome1','t3://localhost:7001')
serverNames = getServerNames()
domainRuntime()
for name in serverNames:
serverState = serverStatus(name.getName())
print serverState
print 'End of script ...'
and it is still failing with a funny output:
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
starting the script ....
End of script ...
Am I possibly missing some libraries in the Eclipse? The Eclipse is throwing many warning for "Undefined variables" which are by default int he WLST like:
cmo
domainConfig()
connect
etc,
Kind Regards,
Loukas
Hi Lokus,
With your comment I started using OEPE first time. Initially I had seen similar issue when I directly tried out the sample WLST script. To find the mystery I build the script from the scratch. newWLST.py run as WLST Run. Then after finding SUCCESS print in the output then started editing the script. It works many times unstoppable then onwards :)
I had refer http://biemond.blogspot.com/2010/08/wlst-scripting-with-oracle-enterprise.html
Now I am pasting the same code which you tried I got the output:
#Conditionally import wlstModule only when script is executed with jython
def serverStatus(server):
cd('/ServerLifeCycleRuntimes/' +server)
return cmo.getState()
if __name__ == '__main__':
from wlstModule import *#@UnusedWildImport
print 'starting the script ....'
username = 'weblogic'
password = 'weblogic1033'
url='t3://localhost:7001'
connect(username,password,url)
try:
print "script returns SUCCESS"
domainConfig()
serverNames = cmo.getServers()
domainRuntime()
for name in serverNames:
print name.getName()
print serverStatus(name.getName())
except Exception, e:
print e
print "Error while trying to save and/or activate!!!"
dumpStack()
raise
I've been looking for just such functionality since I discovered WLST. I've got the script running BUT it only reports on the status of the first of about a dozen Server instances that I have configured. What could be going wrong?
- CDM
Hey CDM,
The script which I had posted that is working for me more than 70 servers without any hassle. I m not clear about your problem with number of servers. Are you able to get the Exception?
What does it tells you?
There's no exception being thrown. The script appears to work fine but it's only returning results for the first server in the list:
Here are all the servers that I have:
wls:/testEnvironment/serverConfig> ls('Servers')
dr-- AdminServer
dr-- alfrescocloneServer
dr-- alfrescoclonesandboxServer
dr-- boweb1Server
dr-- boweb2Server
dr-- ctrac1Server
dr-- ctrac2Server
dr-- ctrac3Server
dr-- ctrac4Server
dr-- esp1Server
dr-- esp2Server
dr-- qualitycentreServer
This is what the script is returning:
Fetching state of every WebLogic instance
Server AdminServer is :RUNNING
Re-Run the script HIT any key..
Are you sure Quit from WLST... (y/n)y
after 20 line print servers
give me reply
Sorry but I'm not sure what you mean by that?
- CDM
From which file it wil get the status of the servers.
I want to manually check the status of the admin server not from console. is there any other ways to find the status........
@Chinni, you have two options. you can redirect the smart script as posted above and read it. Other option is on the first script you can print the state of managed server to a file instead of Standard output. You need to use Jython File operation.
write back your updates... :)
Hi Pavan,
I am running this script as is (modifying the credentials and admin URL) and it is only printing the admin server state (managed are running fine as I see from the console).
I put a print statement after line 20 and its output is:
array([[MBeanServerInvocationHandler]com.bea:Name=CAMAdminServer,Type=Server, [MBeanServerInvocationHandler]com.bea:Name=CAMServer1,Type=Server, [MBeanServerInvocationHandler]com.bea:Name=CAMServer2,Type=Server, [MBeanServerInvocationHandler]com.bea:Name=CAMServer3,Type=Server, [MBeanServerInvocationHandler]com.bea:Name=CAMServer4,Type=Server], weblogic.management.configuration.ServerMBean)
I see that it is returning all the servers, but not printing the status for any of the managed servers. It only prints the first server in the list (the admin):
Server CAMAdminServer is :RUNNING
Re-Run the script HIT any key..
Are you sure Quit from WLST... (y/n)
Any ideas why it would be doing that? and how can i get it to display state of all the managed servers as well?
the script was made for WebLogic 9 version. may be that is the reason.
20 is looking for server names. you might get it by get(Name)
For 10.3 use:
domainRuntime()
for server in cmo.getServerLifeCycleRuntimes():
serverName = server.getName()
serverState = server.getState()
Before choosing your domain you get it which type of hosting services. windows hosting is best choice. because windows is platform independent.website hosting
web hosting
Thanks for sharing, well done. But the guy saying the script only shows admin server is right. you need to put the quit() call out of the loop. Moving at the end of the main made the trick for me.
I really liked ur blog..It has helped me a lot.
Keep posting
Regards,
Fabian
Post a Comment