Script to fire GC using WLST
Linux:
#/usr/bin/env python
export CLASSPATH=$CLASSPATH:/opt/ java1001/bin::/bea/track10200/ wlserver_10.0/server/lib/ weblogic.jar
export PATH=$PATH:/opt/java1001/bin:: /bea/track10200/wlserver_10.0/ server/lib/weblogic.jar::/usr/ bin
/bea/track10200/wlserver_10.0/ server/bin/setWLSEnv.sh
/bea/track10200/user_projects/ domains/track10200/bin/ setDomainEnv.sh
while true
do
java weblogic.WLST /bea/track10200/scripts/ python/gc.py ls -al | tee -a /bea/track10200/scripts/logs/ heapmonitor.out
tempfile=heapmonitor.out
if [ -f $tempfile ]; then rm $tempfile;fi
sleep 5m
sed -i -e '/Welcome*/d' -e '/Initializing*/d' -e '/Type help()*/d' -e '/^ *$/d' /bea/track10200/scripts/logs/ heapmonitor.out
done
Python:
import os
import time
localtime = time.asctime(time.localtime( time.time()))
if __name__ == "__main__":
from wlstModule import *#@UnusedWildImport
print 'starting the script ....'
redirect('/dev/null','false')
connect('username','password','adminurl')
domainRuntime()
cd('ServerRuntimes')
servers=domainRuntimeService. getServerRuntimes();
print '================='+ localtime + '========================'
print 'Garbage collections performed will be logged below.'
for server in servers:
try:
cd("/ServerRuntimes/"+server. getName()+"/JVMRuntime/"+ server.getName())
if int(get('HeapFreePercent'))< 20:
cmo.runGC()
print "*> Finished garbage collect on.." +server.getName()
freejvm = long(get('HeapFreeCurrent'))/( 1024*1024)
totaljvm = long(get('HeapSizeCurrent'))/( 1024*1024)
usedjvm = (totaljvm - freejvm)
print server.getName()+ '\tTotal:' + str(totaljvm) + 'MB' '\tFree:' +str(freejvm) + 'MB' '\tUsed:' +str(usedjvm)+'MB'
except WLSTException,e:
print e
print '============================= ============================== ======='
disconnect()
exit()
No comments:
Post a Comment