7 Getting Runtime Information

You can use the WebLogic Scripting Tool (WLST) to retrieve information that WebLogic Server instances produce to describe their run-time state, configure logging, and use the WebLogic Diagnostic Framework.

Accessing Runtime Information: Main Steps

The Administration Server hosts the domain runtime hierarchy, which provides domain-wide runtime MBeans and access to runtime MBeans exposed by servers in the domain. Use this hierarchy to monitor domain and server runtime information with WLST.

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.
    domainRuntime()
    cd('/')

    The domainRuntime() command selects the domain runtime hierarchy; cd('/') selects its root 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.
    # Starting at ServerRuntimes/myserver:
    cd('JVMRuntime/myserver')
    ls()
    
    -r-- HeapFreeCurrent 130361120
    -r-- HeapFreePercent 74
    -r-- HeapSizeCurrent 268435456
    -r-- HeapSizeMax 536870912
    -r-- JavaVMVendor Oracle Corporation
    -r-- JavaVendor Oracle Corporation
    -r-- JavaVendorVersion null
    -r-- JavaVersion 17.0.8.0.1
    -r-- Name myserver
    -r-- OSName Linux
    -r-- OSVersion 4.14.35-1902.4.8.el7uek.x86_64
    -r-- Type JVMRuntime
    -r-- Uptime 104166
    
    -r-x runGC 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

Example 7-1 checks a Managed Server’s lifecycle state, pausing five seconds between checks. If the state is SHUTDOWN, it starts the server through Node Manager. It reports other states without starting or resuming the server. WLST must already be connected to the Administration Server, and Node Manager must be configured and running for the Managed Server. Replace myserver with the Managed Server name.

Example 7-1 Monitoring Server State

import time

def checkHealth(serverName):
    domainRoot = domainRuntimeService.getDomainRuntime()
    lifecycle = domainRoot.lookupServerLifeCycleRuntime(serverName)
    if lifecycle is None:
        raise ValueError('No configured server named ' + serverName)
    while True:
        status = lifecycle.getState()
        print 'Status of Managed Server is ' + status
        if status == 'SHUTDOWN':
            print 'Starting server ' + serverName
            start(serverName, 'Server', block='true')
        time.sleep(5)

checkHealth('myserver')

Script for Monitoring the JVM

Example 7-2 reads JVMRuntimeMBean.HeapSizeCurrent, in bytes, for servers with available runtime MBeans. It prints a warning when the value exceeds the threshold and pauses three minutes after each complete polling pass. The example connects to the Administration Server at t3://localhost:7001; replace the connection values for your environment.

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

Example 7-2 Monitoring the JVM Heap Size

import time

WAIT_SECONDS = 180
THRESHOLD = 300000000
adminUser = 'adminusername'
adminPassword = 'adminpassword'
adminURL = 't3://localhost:7001'

def monitorJVMHeapSize():
    connect(adminUser, adminPassword, adminURL)
    while True:
        domainRuntime()
        servers = domainRuntimeService.getServerRuntimes()
        for server in servers:
            serverName = server.getName()
            print 'Now checking ' + serverName
            try:
                path = '/ServerRuntimes/' + serverName
                path += '/JVMRuntime/' + serverName
                cd(path)
                heapSize = cmo.getHeapSizeCurrent()
                if heapSize > THRESHOLD:
                    print 'WARNING: Heap size exceeds the threshold'
                else:
                    print heapSize
            except WLSTException as error:
                print 'Unable to read heap size: ' + str(error)
        time.sleep(WAIT_SECONDS)

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 7-3 sets attributes of LogMBean (which extends LogFileMBean). For information on how to run this script, see Invoking WLST.

Example 7-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.

To view 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: