使用python腳本監控weblogic


1.python的腳本如下:

  1 ###############################################################################
  2 #created on 2013-07-09
  3 #author : zhaolijun
  4 #used to get weblogic  server runtime infomation
  5 #wls_ver:weblogic 10.3.5.0
  6 ###############################################################################
  7 
  8 ###############################################################################
  9 # parameters define
 10 ###############################################################################
 11 username='weblogic'
 12 password='isp902isp'
 13 url='t3://10.200.36.210:17101'
 14 LOOPS=3
 15 IntervalTime=30000
 16 FILEPATH="e:/logs/"
 17 newline = "\n"
 18 ###############################################################################
 19 # define functions
 20 ###############################################################################
 21 def WriteToFile(ServerName, SubModule, LogString, LSTARTTIME, FILENAME):
 22 
 23     if SubModule == "ServerCoreInfo":
 24         HeadLineInfo = "DateTime,ServerName,ExecuteThreadIdleCount,StandbyThreadCount,ExecuteThreadTotalCount,busythread,HoggingThreadCount"
 25     elif SubModule == "DataSourceInfo":
 26         HeadLineInfo = "DateTime,ServerName,DataSourceName,ActiveConnectionsCurrentCount,CurrCapacity,WaitingForConnectionCurrentCount,WaitingForConnectionTotal"
 27             
 28     if not os.path.exists(FILENAME): 
 29         print  "path not exist, create log file by self."
 30         f = open(FILENAME, "a+")
 31         f.write(HeadLineInfo + newline)
 32         f.write(LSTARTTIME + "," + ServerName + "," + LogString + newline)
 33         f.close()
 34         f = None
 35     else:
 36         f = open(FILENAME, "a+")    
 37         f.write(LSTARTTIME + "," + ServerName + ","  + LogString + newline)
 38         f.close()
 39         f = None
 40     
 41 def getCurrentTime():
 42     s=SimpleDateFormat("yyyyMMdd HHmmss")
 43     currentTime=s.format(Date())
 44     return currentTime
 45 def GetJdbcRuntimeInfo():
 46     domainRuntime()
 47     servers = domainRuntimeService.getServerRuntimes();
 48     print ' ******************DATASOURCE CONNECTION POOL RUNTIME INFORMATION*******'
 49     for server in servers:   
 50         print 'SERVER: ' + server.getName();
 51         ServerName=server.getName()
 52         jdbcRuntime = server.getJDBCServiceRuntime();
 53         datasources = jdbcRuntime.getJDBCDataSourceRuntimeMBeans();
 54         for datasource in datasources:
 55             ds_name=datasource.getName()
 56             print('-Data Source: ' + datasource.getName() + ', Active Connections: ' + repr(datasource.getActiveConnectionsCurrentCount()) + ', CurrCapacity: ' + repr(datasource.getCurrCapacity())+' , WaitingForConnectionCurrentCount: '+repr(datasource.getWaitingForConnectionCurrentCount())+' , WaitingForConnectionTotal: '+str(datasource.getWaitingForConnectionTotal()));
 57             FILENAME=FILEPATH + ServerName +"_"+ ds_name + "_"+ "DataSourceInfo" +".csv"
 58             LSTARTTIME=getCurrentTime()
 59             dsLogString=ds_name +','+ str(datasource.getActiveConnectionsCurrentCount())+','+repr(datasource.getCurrCapacity())+','+str(datasource.getWaitingForConnectionCurrentCount())+','+str(datasource.getWaitingForConnectionTotal())
 60             WriteToFile(ServerName, "DataSourceInfo", dsLogString, LSTARTTIME, FILENAME)
 61             
 62 def GetThreadRuntimeInfo():
 63     domainRuntime()
 64     servers=domainRuntimeService.getServerRuntimes();
 65     print ' ******************SERVER QUEUE THREAD RUNTIME INFOMATION***************'
 66     for server in servers:
 67         print 'SERVER: ' + server.getName()
 68         ServerName=server.getName()
 69         threadRuntime=server.getThreadPoolRuntime()
 70         hoggingThreadCount = str(threadRuntime.getHoggingThreadCount())
 71         idleThreadCount = str(threadRuntime.getExecuteThreadIdleCount())
 72         standbycount = str(threadRuntime.getStandbyThreadCount())
 73         threadTotalCount = str(threadRuntime.getExecuteThreadTotalCount())
 74         busythread=str(threadRuntime.getExecuteThreadTotalCount()-threadRuntime.getStandbyThreadCount()-threadRuntime.getExecuteThreadIdleCount()-1)
 75         print ('-Thread :' + 'idleThreadCount:' + idleThreadCount+' ,standbycount:'+standbycount+' , threadTotalCount: '+threadTotalCount+' , hoggingThreadCount:'+hoggingThreadCount+' ,busythread:'+busythread)
 76         FILENAME=FILEPATH + ServerName +"_"+ "ServerCoreInfo" +".csv"
 77         LSTARTTIME=getCurrentTime()
 78         serLogString=idleThreadCount+','+standbycount+','+threadTotalCount+','+busythread+','+hoggingThreadCount
 79         WriteToFile(ServerName, "ServerCoreInfo", serLogString, LSTARTTIME, FILENAME)
 80 ###############################################################################
 81 ############ main 
 82 ###############################################################################               
 83 if __name__ == '__main__': 
 84     from wlstModule import *#@UnusedWildImport
 85 #import sys, re, os
 86 #import java
 87 from java.util import Date
 88 from java.text import SimpleDateFormat
 89 print 'starting the script ....'
 90 connect(username,password, url);
 91 try:
 92     for i in range(LOOPS) :
 93         
 94         GetThreadRuntimeInfo()
 95         GetJdbcRuntimeInfo()
 96         java.lang.Thread.sleep(IntervalTime)
 97         
 98 except Exception, e:
 99     print e 
100     dumpStack()
101     raise 
102 disconnect() 
ColletRuntime.py

2.將腳本放到weblogic的安裝目錄D:\weblogic\bea\wlserver_10.3\common\bin下
3.修改collectionRuntime.py中的weblogic的用戶名,密碼,IP,端口,日志路徑修改成正確的數據。

4.打開CMD窗口,切換到D:\weblogic\bea\wlserver_10.3\common\bin下,然后執行命令wlst.cmd CollectRuntime.py

5.在日志路徑下會看到自動生成的CSV文件。能看到HoggingThread和busyThread的數據。

監控gc執行情況的方法如下:

1. 首先需要安裝jdk,在jdk/bin目錄下,例如:C:\Program Files (x86)\Java\jdk1.6.0_10\bin

2. 打開CMD窗口,切換到jdk/bin目錄下,使用命令jstat -gcutil 4556 5s 100 >d:/jstat/text.log ,其中的4556為服務器的進程號。通過jconsole查詢得出。

使用 > d:/jstat/text.log的方式可以將jstat的輸出結果保存到文件中。

3. 在輸出的結果中,可以看到full gc的輸出結果。

4. 在監控full gc和hogging thread的過程中,adminserver是不用監控的。

計算方法:

1. full gc間隔,使用FGC列計算,最后一項減去第一項,除以場景時間(分)。

2. gc執行時間,使用FGCT列計算,最后一項減去第一項,除以場景的執行時間(秒)。

3. hogging  thread 和 busy thread都是找出最大值即可

至此,監控過程全部完成。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM