7 Getting Runtime Information
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:
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:
-
From WLST offline, use the exportDiagnosticData command, described in WLST Command Reference for Oracle WebLogic Server.
-
From WLST online, use exportDiagnosticDataFromServer command, described in WLST Command Reference for Oracle WebLogic Server.