How to use WLST to generate report Of Oracle Weblogic Server.
Solution
WLST is a JMX Client that you can use to browse WebLogic Server MBeans. A WLST script can be run as the following:- Add WebLogic Server classes to the CLASSPATH environment variable and WL_HOME\server\bin to the PATH environment variable, where WL_HOME refers to the top-level installation directory for WebLogic Server. You can use the setWLSEnv script to set the required variables:
Windows:WL_HOME\server\bin\setWLSEnv.cmd
UNIX:WL_HOME/server/bin/setWLSEnv.sh
- Execute:> java weblogic.WLST /etc/oracle/scripts/server_state.py
# Connect to a WebLogic Server:
connect('weblogic','weblogic1','t3://localhost:7001')
# Change from "serverConfig" JMX tree to "serverRuntime" tree.
serverRuntime()
# Use the following attribute to get the startup time,
# Note that value returned is java long file
# and you have to convert it to a readable date.
actTime = get('ActivationTime')
# Get WebLogic State
thisState = get('State')
# Navigate to the JVMRuntime MBean
cd('JVMRuntime/AdminServer')
# Use the following attribute to get the CPU of the JVM, hence the server:
# You might want to multiply this number by 100 to get a precentage
cpuTime = get('JvmProcessorLoad')*100
# Disconnect from the WebLogic Server
disconnect()
# Import python time package
import time
# Use method 'gmtime' to convert 'ActivationTime' to array of
# Year,Month,Day,Hour,and Seconds
x = time.gmtime(actTime/1000)
print
print
print "Start Time : " + str(x[0]) + "/" + str(x[1]) + "/" + str(x[2]) + " - " + str(x[3]) + ":" + str(x[4])
print "Activation Time: " + str(actTime)
print "State: " + thisState
print "CPU: " + str(cpuTime) + "%"
connect('weblogic','weblogic1','t3://localhost:7001')
# Change from "serverConfig" JMX tree to "serverRuntime" tree.
serverRuntime()
# Use the following attribute to get the startup time,
# Note that value returned is java long file
# and you have to convert it to a readable date.
actTime = get('ActivationTime')
# Get WebLogic State
thisState = get('State')
# Navigate to the JVMRuntime MBean
cd('JVMRuntime/AdminServer')
# Use the following attribute to get the CPU of the JVM, hence the server:
# You might want to multiply this number by 100 to get a precentage
cpuTime = get('JvmProcessorLoad')*100
# Disconnect from the WebLogic Server
disconnect()
# Import python time package
import time
# Use method 'gmtime' to convert 'ActivationTime' to array of
# Year,Month,Day,Hour,and Seconds
x = time.gmtime(actTime/1000)
print "Start Time : " + str(x[0]) + "/" + str(x[1]) + "/" + str(x[2]) + " - " + str(x[3]) + ":" + str(x[4])
print "Activation Time: " + str(actTime)
print "State: " + thisState
print "CPU: " + str(cpuTime) + "%"
IMPORTANT: To use attribute 'JvmProcessorLoad', you need to make sure that your domain options "Platform MBean Server Enabled" and "isPlatformMBeanServerUsed" are enabled, so using 'WLS Administration Console,' go to your domain -> Configuration -> General -> Advanced and enable them. A restart is required here.
WLST should print output like:
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'OHS'.
Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.
Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)
Disconnected from weblogic server: AdminServer
Start Time : 2011/4/30 - 19:13
Activation Time: 1304190828812
State: RUNNING
CPU: 1.8867924528301887%
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'OHS'.
Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.
Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)
Disconnected from weblogic server: AdminServer
Start Time : 2011/4/30 - 19:13
Activation Time: 1304190828812
State: RUNNING
CPU: 1.8867924528301887%
0 Comments