WLST monitoring methods

Auteur:

Ebicus

Datum:

23 juli 2014

Categorie:

WLST

WLST has great potential for monitoring purposes, because of its ability to be scripted. You can use the scripts for continuous monitoring by for example: crontab.

If you want to get the current healthstate of the Weblogic server you can use the method cmo.getHealthState(). This method will return healthstates  in a similar way as the Weblogic Console, i.e. HealthState = HEALTH_OK.

wls:/cp_dev/domainRuntime/ServerRuntimes/AdminServer> cmo.getHealthState()
Component:ServerRuntime,State:HEALTH_OK,MBean:AdminServer,ReasonCode:[]

The method getHealthState() can however, return HEALTH_OK instead of WARNING even, when in the WebLogic Server (WLS) admin console it shows as WARNING.

This is not a bug, but working as designed. The method getHealthState() is meant to report the WARNING if and only if:

  • All threads are stuck.
  • The server memory is below the user-configured low threshold.
  • The open socket threshold has been reached.

getSubsystemHealthStates

A workaround for retrieving the actual health of the Weblogic server is combining the method cmo.getHealthState() with checking the health of the Weblogic subsystems . If one of the subsystems doesn’t have HEALTH_OK, the health of the Weblogic server is compromised. The health of the subsystems can be checked using method cmo.getSubsystemHealthStates(). This will return an array containing the mbeans for the Weblogic subsystems.

wls:/cp_dev/domainRuntime/ServerRuntimes/AdminServer> cmo.getSubsystemHealthStates()
array(weblogic.health.HealthState,[Component:threadpool,State:HEALTH_OK,MBean:ThreadPoolRuntime,ReasonCode:[], Component:bea_wls_internal(Application),State:HEALTH_OK,MBean:bea_wls_internal,ReasonCode:[], Component:ConferencePlanner(Application),State:HEALTH_OK,MBean:ConferencePlanner,ReasonCode:[], Component:JTA,State:HEALTH_OK,MBean:JTARuntime,ReasonCode:[], Component:PersistentStore.WLS_DIAGNOSTICS,State:HEALTH_OK,MBean:WLS_DIAGNOSTICS,ReasonCode:[], Component:ServerRuntime,State:HEALTH_OK,MBean:AdminServer,ReasonCode:[], Component:AdminServer.saf,State:HEALTH_OK,MBean:AdminServer.saf,ReasonCode:[], Component:mejb(Application),State:HEALTH_OK,MBean:mejb,ReasonCode:[], Component:bea_wls9_async_response(Application),State:HEALTH_OK,MBean:bea_wls9_async_response,ReasonCode:[], Component:AdminServer.jms,State:HEALTH_OK,MBean:AdminServer.jms,ReasonCode:[], Component:JDBC,State:HEALTH_OK,MBean:AdminServer,ReasonCode:[], Component:PersistentStore._WLS_AdminServer,State:HEALTH_OK,MBean:_WLS_AdminServer,ReasonCode:[]])

Script example:

## Import the string library
import string

## Connect to adminserver of domain
connect(username, password, URL)

domainRuntime()
cd(‘ServerRuntimes’)

## Get servers in runtime
servers_runtime = domainRuntimeService.getServerRuntimes()

for server in servers_runtime:

## Get health of subsystems (i.e. dbadapter)

components = server.getSubsystemHealthStates()

## Convert to list

componentsList = components.tolist()

## Components with no HEALTH_OK will be added to variable error_message

for component in componentsList:

if not “HEALTH_OK” in str(component):

error_message+=server.getName() + “n” + str(component) + “nn”;

getOverallHealthState

A new WLST method has been introduced in WLS 10.3.6, which combines the methods cmo.getHealthState() and  cmo.getSubsystemHealthStates() and will return the same server health as reported in the admin console. This method is called cmo.getOverallHealthState().

wls:/cp_dev/domainRuntime/ServerRuntimes/AdminServer> cmo.getOverallHealthState()
Component:ServerRuntime,State:HEALTH_OK,MBean:AdminServer,ReasonCode:[]

Script example:

## Import the string library
import string

## Connect to adminserver of domain
connect(username, password, URL)

domainRuntime()
cd(‘ServerRuntimes’)

## Get servers in runtime
servers_runtime = domainRuntimeService.getServerRuntimes()

for server in servers_runtime:

## Get health of servers

serverhealth = server.getOverallHealthState()

## Servers with no HEALTH_OK will be added to variable error_message

if not “HEALTH_OK” in str(serverhealth):

error_message = server.getName() + “n” + str(serverhealth) + “nn”;

Neem contact met op met Pieter voor meer informatie over WLST

Kunnen wij je helpen?

Neem contact op met Ebicus via het contactformulier of raadpleeg direct één van onze collega’s om je direct te ondersteunen!

Bekijk al onze blogs