Monday, June 29, 2015

HTML format output for wlst scripts - Threadpool and server status



1. Download the HTML.py module from the following link http://www.decalage.info/python/html and place this in wlserver_10.3/common/wlst/modules

2. Below script will generate html file upon successful execution and it will be placed in the same directory from where you execute the script

#!/usr/bin/python
import sys
sys.path.insert(0,'/u01/app/oracle/product/fmw/wlserver_10.3/common/wlst/modules/HTML.py')
import HTML
tohtmlfile=open('ThreadPoolStatusHTMLFILE.html', 'w')

def connection():
    try:
        connect(wls_username,wls_password,url);
    except:
        "Unable to connect to the Admin Server, Please check!"
        
def Threadpoolstatus():
    tabledata=HTML.Table(header_row=['Server Name','Status','Completed Requests','Hogging Threads','Total Threads','Idle Threads','Pending','Queue Length','Throughput']);
    urldict={}
    serverConfig()
    serverlist=cmo.getServers()  # Getting Serverlist
    for svr in serverlist:
        cd("/Servers/"+svr.getName());
        urldict[svr.getName()]='t3://'+get('ListenAddress')+':'+str(get('ListenPort'));
    myKeyS = urldict.keys()
    myKeyS.sort()
    print "%7s %7s %7s %7s %7s %7s %7s %7s" % ('ServerName','compReq','hoggingThreads','totalThreads','idleThrds','pending','qLen','thruput');
    for name in myKeyS:
        connect("weblogic","Welcome1",url=urldict[name]);
        ServerName=str(name);
        cd('serverRuntime:/ThreadPoolRuntime/ThreadPoolRuntime/')
        statusstring = str(cmo.getHealthState())
        Status=statusstring.split(',')[1].split(':')[1]
        compReq = cmo.getCompletedRequestCount();
        hoggingThreads = cmo.getHoggingThreadCount();
        totalThreads = cmo.getExecuteThreadTotalCount();
        idleThrds = int(cmo.getExecuteThreadIdleCount());
        pending = cmo.getPendingUserRequestCount();
        qLen = cmo.getQueueLength();
        thruput = cmo.getThroughput();    
        print "%7s %7s %7d %10d %15d %10d %10d %10d" % (ServerName,compReq,hoggingThreads,totalThreads,idleThrds,pending,qLen,thruput)
        if idleThrds == 0 or Status <> 'HEALTH_OK':
            TPstatus = HTML.TableRow([ServerName,Status,compReq,hoggingThreads,totalThreads,idleThrds,pending,qLen,thruput],bgcolor='red')
        else:
            TPstatus = HTML.TableRow([ServerName,Status,compReq,hoggingThreads,totalThreads,idleThrds,pending,qLen,thruput],bgcolor='lime')
        tabledata.rows.append([TPstatus])

    myhtmlcode = tabledata
    print>>tohtmlfile, myhtmlcode

if __name__== "main":
    redirect('threadpoolstatus.log', 'false')
    connection()
    Threadpoolstatus() 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.