Fusion Middleware Documentation
Advanced Search


Understanding the WebLogic Scripting Tool
Close Window

Table of Contents

Show All | Collapse

8 Getting Runtime Information

This chapter describes how to use WebLogic Scripting Tool (WLST) to retrieve information that WebLogic Server instances produce to describe their run-time state.

This chapter includes the following sections:

Accessing Runtime Information: Main Steps

The Administration Server hosts the domain run-time hierarchy which provides access to any MBean on any server in the WebLogic domain. If the Administration Server is not running for a WebLogic domain, WLST can connect to individual Managed Servers to retrieve run-time data.

Accessing the run-time information for a WebLogic domain includes the following main steps:

  1. Invoke WLST and connect to a running Administration Server instance. See Invoking WLST.

  2. Navigate to the domain run-time MBean hierarchy by entering the domainRuntime command.

    wls:/mydomain/serverConfig>domainRuntime() 
    

    The domainRuntime command places WLST at the root of the domain-wide run-time management objects, DomainRuntimeMBean.

  3. Navigate to ServerRuntimes and then to the server instance which you are interested in monitoring.

    wls:/mydomain/domainRuntime>cd('ServerRuntimes/myserver') 
    
  4. At the server instance, navigate to and interrogate run-time MBeans.

    wls:/mydomain/domainRuntime/ServerRuntimes/myserver>cd('JVMRuntime/myserver')> 
    wls:/mydomain/domainRuntime/ServerRuntimes/myserver/JVMRuntime/myserver>ls() 
    
    -r--   HeapFreeCurrent                              191881368
    -r--   HeapFreePercent                              87
    -r--   HeapSizeCurrent                              259588096
    -r--   HeapSizeMax                                  518979584
    -r--   JavaVMVendor                                 Sun Microsystems Inc.
    -r--   JavaVendor                                   Sun Microsystems Inc.
    -r--   JavaVersion                                  1.6.0_21
    -r--   Name                                         AdminServer
    -r--   OSName                                       Windows XP
    -r--   OSVersion                                    5.1
    -r--   Type                                         JVMRuntime
    -r--   Uptime                                       409141
    
    -r-x   preDeregister                                Void :
    ...
    

The following sections provide example scripts for retrieving run-time information about WebLogic Server server instances and WebLogic domain resources.

Script for Monitoring Server State

The WLST online script in Example 8-1 navigates the domain run-time hierarchy and checks the status of a Managed Server every 5 seconds. It restarts the server if the server state changes from RUNNING to any other status. It assumes that WLST is connected to the WebLogic domain's Administration Server.

Example 8-1 Monitoring Server State

# Node Manager needs to be running to run this script.

import thread
import time

def checkHealth(serverName):
  while 1:
    slBean = getSLCRT(serverName)
    status = slBean.getState()
    print 'Status of Managed Server is '+status
    if status != "RUNNING":
      print 'Starting server '+serverName
      start(serverName, block="true")
    time.sleep(5) 

def getSLCRT(svrName):
    domainRuntime()
    slrBean = cmo.lookupServerLifecycleRuntime(svrName)
    return slrBean

checkHealth("myserver")

Script for Monitoring the JVM

The WLST online script in Example 8-2 monitors the HJVMHeapSize for all running servers in a WebLogic domain; it checks the heap size every 3 minutes and prints a warning if the heap size is greater than a specified threshold. It assumes that the URL for the WebLogic domain's Administration Server is t3://localhost:7001.

For information on how to run this script, see Invoking WLST.

Example 8-2 Monitoring the JVM Heap Size

waitTime=180000
THRESHOLD=300000000
uname = "adminusername"
pwd = "adminpassword"
url = "t3://localhost:7001"
def monitorJVMHeapSize():
    connect(uname, pwd, url)
    while 1:
        serverNames = getRunningServerNames()
        domainRuntime()
        for name in serverNames:
            print 'Now checking '+name.getName()
            try:
              cd("/ServerRuntimes/"+name.getName()+"/JVMRuntime/"+name.getName())
              heapSize = cmo.getHeapSizeCurrent()
              if heapSize > THRESHOLD:
              # do whatever is neccessary, send alerts, send email etc
                print 'WARNING: The HEAPSIZE is Greater than the Threshold'
              else:
                print heapSize
            except WLSTException,e:
              # this typically means the server is not active, just ignore
              # pass
                print "Ignoring exception " + e.getMessage()
            java.lang.Thread.sleep(waitTime)
 
def getRunningServerNames():
        # only returns the currently running servers in the domain
        return domainRuntimeService.getServerRuntimes()
 
if __name__== "main":
    monitorJVMHeapSize()

Configuring Logging

Using WLST, you can configure a server instance's logging and message output.

To determine which log attributes can be configured, see "LogMBean" and "LogFileMBean" in the MBean Reference for Oracle WebLogic Server. The reference also indicates valid values for each attribute.

The WLST online script in Example 8-3 sets attributes of LogMBean (which extends LogFileMBean). For information on how to run this script, see Invoking WLST.

Example 8-3 Configuring Logging

# Connect to the server
connect("adminusername","adminpassword","t3://localhost:7001")
edit()
startEdit()

# set CMO to the server log config
cd("Servers/myserver/Log/myserver")
ls ()

# change LogMBean attributes
set("FileCount", 5)
set("FileMinSize", 400)

# list the current directory to confirm the new attribute values
ls ()

# save and activate the changes
save()
activate()

# all done...
exit()

Working with the WebLogic Diagnostics Framework

The WebLogic Diagnostic Framework (WLDF) is a monitoring and diagnostic framework that can collect diagnostic data that servers and applications generate. You configure WLDF to collect the data and store it in various sources, including log records, data events, and harvested metrics. For more information, see Configuring and Using the Diagnostics Framework for Oracle WebLogic Server.

For example scripts that demonstrate using WLST to configure the WebLogic Diagnostic Framework, see "WebLogic Scripting Tool Examples" in Configuring and Using the Diagnostics Framework for Oracle WebLogic Server.

To view the collected diagnostics information using WLST, use one of the following commands to export the data from the WLDF repositories:

  • From WLST offline, use the exportDiagnosticData command (see "exportDiagnosticData" in WebLogic Scripting Tool Command Reference).

  • From WLST online, use the exportDiagnosticDataFromServer command (see "exportDiagnosticDataFromServer" in WebLogic Scripting Tool Command Reference)).