Wednesday, January 11, 2012

Enabling and Using JDBC Logging


Set the classpath variables in setDomainEnv.sh file under the following header
# ADD EXTENSIONS TO CLASSPATHS
On Windows
set EXT_PRE_CLASSPATH=C:\Oracle\Middleware\wlserver_10.3\server\ext\jdbc\oracle\11g\ojdbc6_g.jar 
set JAVA_OPTIONS=-Doracle.jdbc.Trace=true -Djava.util.logging.config.file=c:/temp/OracleLog.properties 


On Unix
EXT_PRE_CLASSPATH="${EXT_PRE_CLASSPATH}${CLASSPATHSEP}/reuters/oracle/product/soa/11g/fmw/wlserver_10.3/server/ext/jdbc/oracle/11g/ojdbc6_g.jar"
JAVA_OPTIONS="${JAVA_OPTIONS} -Doracle.jdbc.Trace=true -Djava.util.logging.config.file=/reuters/oracle/as01/fmw/config/admin/domains/deployplan/OracleLog.properties "

In the OracleLog.properties have the following entries ,
#### Console Handler ######
#java.util.logging.ConsoleHandler.level = ALL 
#java.util.logging.ConsoleHandler.formatter =
 
#java.util.logging.SimpleFormatter
 
#handlers = java.util.logging.ConsoleHandler
#### File  Handler ######
oracle.jdbc.handlers=java.util.logging.FileHandler 
java.util.logging.FileHandler.level=ALL
 
java.util.logging.FileHandler.pattern=c:/temp/jdbc.log
 
java.util.logging.FileHandler.count=1
 
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
# Uncomment and/or change the levels for more detail 
#oracle.jdbc.level = FINEST
 
#oracle.jdbc.connector.level = FINE
 
#oracle.jdbc.driver.level = FINEST
 
#oracle.jdbc.internal.level = FINEST
 
#oracle.jdbc.oci.level = FINE
 
#oracle.jdbc.oracore.level = FINE
 
#oracle.jdbc.pool.level = FINE
 
#oracle.jdbc.rowset.level = FINEST
 
#oracle.jdbc.util.level = FINEST
 
#oracle.jdbc.xa.level = FINE
 
#oracle.jdbc.xa.client.level = FINE
 
#oracle.jpub.level = FINE
 
#oracle.net.level = FINE
 
#oracle.sql.level = FINEST
 
#.level=CONFIG
 
#oracle.level=CONFIG
 
#oracle.jdbc.pool.level=CONFIG
 
#oracle.jdbc.util.level=CONFIG
 
#oracle.sql.level=CONFIG
#oracle.jdbc.driver.level=FINE

# This is the setting needed for sql debug
 
oracle.jdbc.driver.level=FINE
 
oracle.level=OFF
 If you want only the sql statements without bind variables use 
oracle.jdbc.driver.level=CONFIG

Tuesday, January 3, 2012

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()