WLST Script to Monitor Weblogic Server State
import thread
import time
def conn():
username='weblogic'
password='welcome1'
admurl = "t3://localhost:7001"
try:
connect(username, password, admurl)
except ConnectionException,e:
print 'Unable to find admin server...'
exit()
def ServrState():
print 'Fetching state of every WebLogic instance'
#Fetch the state of the every WebLogic instance
for name in serverNames:
cd("/ServerLifeCycleRuntimes/" + name.getName())
serverState = cmo.getState()
if serverState == "RUNNING":
print 'Server ' + name.getName() + ' is :' + serverState
elif serverState == "STARTING":
print 'Server ' + name.getName() + ' is :' + serverState
elif serverState == "UNKNOWN":
print 'Server ' + name.getName() + ' is :' + serverState
else:
print 'Server ' + name.getName() + ' is :' + serverState
def ApplicationsState():
print 'Fetching state of every Application deployed on Weblogic'
for appName in myapps:
domainConfig()
cd ('/AppDeployments/'+appName.getName()+'/Targets')
mytargets = ls(returnMap='true')
domainRuntime()
cd('AppRuntimeStateRuntime')
cd('AppRuntimeStateRuntime')
for targetinst in mytargets:
appID = appName.getApplicationIdentifier()
navPath=getMBean('domainRuntime:/AppRuntimeStateRuntime/AppRuntimeStateRuntime')
sts=navPath.getCurrentState(appID,targetinst)
print "Status of " + appName.getApplicationName() + ": " + sts + ": " + targetinst
print "==========================================================================="
def monitorJVMHeapSize():
#while 1:
for name in serverNames:
print 'Now checking '+name.getName()
try:
cd("/ServerRuntimes/"+name.getName()+"/JVMRuntime/"+name.getName())
except WLSTException,e:
# this typically means the server is not active, just ignore
pass
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
#java.lang.Thread.sleep(1800000)
def quit():
print 'Re-Run the script HIT any key..'
Ans = raw_input("Are you sure Quit from WLST... (y/n)")
if (Ans == 'y'):
disconnect()
stopRedirect()
exit()
else:
ServrState()
if __name__== "main":
#waitTime=300000
THRESHOLD=100000000
redirect('./logs/Server.log', 'false')
conn()
serverNames = cmo.getServers()
myapps = cmo.getAppDeployments()
domainRuntime()
ServrState()
ApplicationsState()
monitorJVMHeapSize()
quit()
import thread
import time
def conn():
username='weblogic'
password='welcome1'
admurl = "t3://localhost:7001"
try:
connect(username, password, admurl)
except ConnectionException,e:
print 'Unable to find admin server...'
exit()
def ServrState():
print 'Fetching state of every WebLogic instance'
#Fetch the state of the every WebLogic instance
for name in serverNames:
cd("/ServerLifeCycleRuntimes/" + name.getName())
serverState = cmo.getState()
if serverState == "RUNNING":
print 'Server ' + name.getName() + ' is :' + serverState
elif serverState == "STARTING":
print 'Server ' + name.getName() + ' is :' + serverState
elif serverState == "UNKNOWN":
print 'Server ' + name.getName() + ' is :' + serverState
else:
print 'Server ' + name.getName() + ' is :' + serverState
def ApplicationsState():
print 'Fetching state of every Application deployed on Weblogic'
for appName in myapps:
domainConfig()
cd ('/AppDeployments/'+appName.getName()+'/Targets')
mytargets = ls(returnMap='true')
domainRuntime()
cd('AppRuntimeStateRuntime')
cd('AppRuntimeStateRuntime')
for targetinst in mytargets:
appID = appName.getApplicationIdentifier()
navPath=getMBean('domainRuntime:/AppRuntimeStateRuntime/AppRuntimeStateRuntime')
sts=navPath.getCurrentState(appID,targetinst)
print "Status of " + appName.getApplicationName() + ": " + sts + ": " + targetinst
print "==========================================================================="
def monitorJVMHeapSize():
#while 1:
for name in serverNames:
print 'Now checking '+name.getName()
try:
cd("/ServerRuntimes/"+name.getName()+"/JVMRuntime/"+name.getName())
except WLSTException,e:
# this typically means the server is not active, just ignore
pass
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
#java.lang.Thread.sleep(1800000)
def quit():
print 'Re-Run the script HIT any key..'
Ans = raw_input("Are you sure Quit from WLST... (y/n)")
if (Ans == 'y'):
disconnect()
stopRedirect()
exit()
else:
ServrState()
if __name__== "main":
#waitTime=300000
THRESHOLD=100000000
redirect('./logs/Server.log', 'false')
conn()
serverNames = cmo.getServers()
myapps = cmo.getAppDeployments()
domainRuntime()
ServrState()
ApplicationsState()
monitorJVMHeapSize()
quit()
No comments:
Post a Comment