WLST : get runtime data iterating on instances

In the WebLogic console you may find that is difficult to do a fast check on a runtime property for all the configured managed instances of a domain.

Here you’ll find how to do it by using WLST interactively.

Note: this sample was tested with “WebLogic Server 10.3.5.0”.

After loading the environment (. ./setDomainEnv.sh) and running the WLST console (see Oracle WLS 10.3.5 Documentation – Using WLST) you’ll connect to the administrative instance by using the command

connect(username,password,'t3s://myhost:8001')

You’ll collect the managed servers into “serverNames” variable by going to the Domain Config MBean tree:

wls:/MYDOMAIN/serverConfig> domainConfig()
wls:/MYDOMAIN/domainConfig> serverNames = cmo.getServers()

After that you have to go to the Domain Runtime MBean tree, cycle through the servers and get the desired runtime property (in this sample the “Activation Time”):

wls:/MYDOMAIN/domainConfig> domainRuntime()
wls:/MYDOMAIN/domainRuntime/ServerRuntimes> for name in serverNames:
...     print name
...     cd("/ServerRuntimes/"+name.getName())
...     print java.util.Date(cmo.getActivationTime())
...

Tip: (python syntax) the white space before commands inside the “for” cycle are TAB characters. They are needed to tell the Jython interpreter that the commands must be executed inside the “for” cycle. To end the cycle in the last void line press enter without typing the tab…

Tip: Since WebLogic is implemented with Java, all the values are java-type values. To convert the date value into readable format you must use java.util.Date(<date-value>)

To retrieve other attributes of the ServerRuntime you can refer to the MBean documentation WLS 10.3.5 ServerRuntime Attributes and call “cmo.get<attribute>”.

Improvement: do not exit loop if some instance is not responding.

If one instance is down or not responding the loop will exit. To avoid this you can use the try-except python syntax.

for name in serverNames:
    print name
    try :
        cd("/ServerRuntimes/"+name.getName())
        print java.util.Date(cmo.getActivationTime())
    except WLSTException :
        print "ERROR Detected"

Please note that WLSTException is the exception object type returned when the instance is not up. If you want to catch more exception object types you can use the parenthesis syntax: except (WLSTException, NullPointerException) :