如何使用Weblogic中的WLST脚本获取应用程序部署状态

时间:2014-10-12 11:34:46

标签: python weblogic-10.x wlst

我使用下面的脚本来监视我的weblogic资源,比如JDBC,JMS,但我想监视我的Weblogic服务器中部署的应用程序状态。

将部署监控脚本添加到其中的任何帮助都将是一个很大的帮助。

提前致谢!!!

###########################################################################

import sys
username=sys.argv[1]
password=sys.argv[2]
connectUrl=sys.argv[3]

urldict={}
connect(username,password,connectUrl)
serverlist=adminHome.getMBeansByType('Server')
f_out=open('../reports/'+domainName+'_status.txt','w')

for svr in serverlist:
            urldict[svr.getName()]='t3://'+svr.getListenAddress()+':'+str(svr.getListenPort())
            print svr.getListenAddress() + ":" + str(svr.getListenPort())
disconnect()

for svr,url in urldict.items():
                try:    
                    username=sys.argv[1]
                    connect(username,password,url)

                    try:    
                        cur_state=home.getMBeansByType('ServerRuntime')
                        for c in cur_state:
                                    ser_name=c.getAttribute('Name')
                                    ser_state=c.getAttribute('State')
                                    print >> f_out, 'Server Status -',ser_name,':',ser_state
                    except  Exception, e0:
                                print 'Exception occurred while getting server status '+svr

                    try:    
                        jmsrtlist=home.getMBeansByType('JMSDestinationRuntime')

                        for jmsRT in jmsrtlist:
                                    jmsname = jmsRT.getAttribute("Name")
                                    jmsmcc = jmsRT.getAttribute("MessagesCurrentCount")
                                    jmsmpc = jmsRT.getAttribute("MessagesPendingCount")
                                    jmsmrc = jmsRT.getAttribute("MessagesReceivedCount")
                                    jmsctc = jmsRT.getAttribute("ConsumersCurrentCount")
                                    jmspar = jmsRT.getAttribute("Parent")
                                    #jmscpss = jmsRT.getAttribute("ConsumptionPausedState")
                                    #jmsppss = jmsRT.getAttribute("ProductionPausedState")
                                    jmscps = jmsRT.isConsumptionPaused()
                                    jmspps = jmsRT.isProductionPaused()
                                    jmsips = jmsRT.isInsertionPaused()
                                    jmsmhc = jmsRT.getAttribute("MessagesHighCount")
                                    print >> f_out, 'JMS Queue -', svr,':',jmsname,',',jmsmcc,',',jmsmpc,',',jmsmhc,',',jmsmrc,',',jmsctc,',',jmscps,',',jmspps,',',jmsips
                    except  Exception, e1:
                                print 'Exception occurs while getting values for server '+svr

                    try:
                        poolrtlist=home.getMBeansByType('JDBCConnectionPoolRuntime')
                        for poolRT in poolrtlist:
                                    pname = poolRT.getName()
                                    pmaxcapacity = poolRT.getAttribute("MaxCapacity")
                                    paccc = poolRT.getAttribute("ActiveConnectionsCurrentCount")
                                    pachc = poolRT.getAttribute("ActiveConnectionsHighCount")
                                    pwshc = poolRT.getAttribute("WaitSecondsHighCount")
                                    pwfccc = poolRT.getAttribute("WaitingForConnectionCurrentCount")
                                    pstate = poolRT.getAttribute("State")
                                    print >> f_out, 'JDBC Datasource -', svr,':',pname,',',pstate,',',pmaxcapacity,',',paccc,',',pachc
                    except  Exception, e2:
                                print 'Exception occurs while getting values for server '+svr  

                    try:
                        jvmrtlist=home.getMBeansByType('JVMRuntime')
                        for jvmRT in jvmrtlist:
                                    freejvm = jvmRT.getAttribute("HeapFreeCurrent")
                                    totaljvm = jvmRT.getAttribute("HeapSizeCurrent")
                                    #usedjvm = (totaljvm - freejvm)
                                    print >> f_out, 'JVM Runtime -', svr,':',totaljvm/1048576,',',freejvm/1048576
                    except  Exception, e3:
                                print 'Exception occurs while getting values for server '+svr
                    try:
                        jvmrtlist=home.getMBeansByType('JRockitRuntime')
                        for jvmRT in jvmrtlist:
                                    freejvm = jvmRT.getAttribute("HeapFreeCurrent")
                                    totaljvm = jvmRT.getAttribute("HeapSizeCurrent")
                                    #usedjvm = (totaljvm - freejvm)
                                    print >> f_out, 'JVM Runtime -', svr,':',totaljvm/1048576,',',freejvm/1048576
                    except  Exception, e3:
                                print 'Exception occurs while getting values for server '+svr


                    try:
                        mblist=home.getMBeansByType('MessagingBridgeRuntime')
                        for mbRT in mblist:
                                    mbname = mbRT.getAttribute("Name")
                                    mbstate = mbRT.getAttribute("State")
                                    mbdesc = mbRT.getAttribute("Description")
                                    print >> f_out, 'JMS Bridge -', svr + ':' + mbname +',' + mbdesc
                    except  Exception, e5:
                                print 'Exception occurs while getting values for server '+svr

                    try:
                        serverRuntime()
                        eqname = get('ThreadPoolRuntime/ThreadPoolRuntime/Name')
                        eqtthreads = get("ThreadPoolRuntime/ThreadPoolRuntime/ExecuteThreadTotalCount")
                        eqithreads = get("ThreadPoolRuntime/ThreadPoolRuntime/ExecuteThreadIdleCount")
                        eqstc = get("ThreadPoolRuntime/ThreadPoolRuntime/StandbyThreadCount") 
                        print >> f_out, 'Thread Runtime -', svr,':',eqname,',',eqithreads,',',eqstc,',',eqtthreads
                    except  Exception, e6:
                                print 'Exception occurs while getting values for server '+svr

                except Exception, e:
                            print >> f_out, 'Server Status -', svr ,':' ,'NOT RUNNING'          

f_out.close()
disconnect()
exit()

0 个答案:

没有答案