使用python脚本监控weblogic

1.python的脚本如下:

 ###############################################################################
#created on 2013-07-09
#author : zhaolijun
#used to get weblogic server runtime infomation
#wls_ver:weblogic 10.3.5.0
############################################################################### ###############################################################################
# parameters define
###############################################################################
username='weblogic'
password='isp902isp'
url='t3://10.200.36.210:17101'
LOOPS=3
IntervalTime=30000
FILEPATH="e:/logs/"
newline = "\n"
###############################################################################
# define functions
###############################################################################
def WriteToFile(ServerName, SubModule, LogString, LSTARTTIME, FILENAME): if SubModule == "ServerCoreInfo":
HeadLineInfo = "DateTime,ServerName,ExecuteThreadIdleCount,StandbyThreadCount,ExecuteThreadTotalCount,busythread,HoggingThreadCount"
elif SubModule == "DataSourceInfo":
HeadLineInfo = "DateTime,ServerName,DataSourceName,ActiveConnectionsCurrentCount,CurrCapacity,WaitingForConnectionCurrentCount,WaitingForConnectionTotal" if not os.path.exists(FILENAME):
print "path not exist, create log file by self."
f = open(FILENAME, "a+")
f.write(HeadLineInfo + newline)
f.write(LSTARTTIME + "," + ServerName + "," + LogString + newline)
f.close()
f = None
else:
f = open(FILENAME, "a+")
f.write(LSTARTTIME + "," + ServerName + "," + LogString + newline)
f.close()
f = None def getCurrentTime():
s=SimpleDateFormat("yyyyMMdd HHmmss")
currentTime=s.format(Date())
return currentTime
def GetJdbcRuntimeInfo():
domainRuntime()
servers = domainRuntimeService.getServerRuntimes();
print ' ******************DATASOURCE CONNECTION POOL RUNTIME INFORMATION*******'
for server in servers:
print 'SERVER: ' + server.getName();
ServerName=server.getName()
jdbcRuntime = server.getJDBCServiceRuntime();
datasources = jdbcRuntime.getJDBCDataSourceRuntimeMBeans();
for datasource in datasources:
ds_name=datasource.getName()
print('-Data Source: ' + datasource.getName() + ', Active Connections: ' + repr(datasource.getActiveConnectionsCurrentCount()) + ', CurrCapacity: ' + repr(datasource.getCurrCapacity())+' , WaitingForConnectionCurrentCount: '+repr(datasource.getWaitingForConnectionCurrentCount())+' , WaitingForConnectionTotal: '+str(datasource.getWaitingForConnectionTotal()));
FILENAME=FILEPATH + ServerName +"_"+ ds_name + "_"+ "DataSourceInfo" +".csv"
LSTARTTIME=getCurrentTime()
dsLogString=ds_name +','+ str(datasource.getActiveConnectionsCurrentCount())+','+repr(datasource.getCurrCapacity())+','+str(datasource.getWaitingForConnectionCurrentCount())+','+str(datasource.getWaitingForConnectionTotal())
WriteToFile(ServerName, "DataSourceInfo", dsLogString, LSTARTTIME, FILENAME) def GetThreadRuntimeInfo():
domainRuntime()
servers=domainRuntimeService.getServerRuntimes();
print ' ******************SERVER QUEUE THREAD RUNTIME INFOMATION***************'
for server in servers:
print 'SERVER: ' + server.getName()
ServerName=server.getName()
threadRuntime=server.getThreadPoolRuntime()
hoggingThreadCount = str(threadRuntime.getHoggingThreadCount())
idleThreadCount = str(threadRuntime.getExecuteThreadIdleCount())
standbycount = str(threadRuntime.getStandbyThreadCount())
threadTotalCount = str(threadRuntime.getExecuteThreadTotalCount())
busythread=str(threadRuntime.getExecuteThreadTotalCount()-threadRuntime.getStandbyThreadCount()-threadRuntime.getExecuteThreadIdleCount()-1)
print ('-Thread :' + 'idleThreadCount:' + idleThreadCount+' ,standbycount:'+standbycount+' , threadTotalCount: '+threadTotalCount+' , hoggingThreadCount:'+hoggingThreadCount+' ,busythread:'+busythread)
FILENAME=FILEPATH + ServerName +"_"+ "ServerCoreInfo" +".csv"
LSTARTTIME=getCurrentTime()
serLogString=idleThreadCount+','+standbycount+','+threadTotalCount+','+busythread+','+hoggingThreadCount
WriteToFile(ServerName, "ServerCoreInfo", serLogString, LSTARTTIME, FILENAME)
###############################################################################
############ main
###############################################################################
if __name__ == '__main__':
from wlstModule import *#@UnusedWildImport
#import sys, re, os
#import java
from java.util import Date
from java.text import SimpleDateFormat
print 'starting the script ....'
connect(username,password, url);
try:
for i in range(LOOPS) : GetThreadRuntimeInfo()
GetJdbcRuntimeInfo()
java.lang.Thread.sleep(IntervalTime) except Exception, e:
print e
dumpStack()
raise
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都是找出最大值即可

至此,监控过程全部完成。

上一篇:我的sql数据库存储过程分页- -


下一篇:VMware中为CentOS配置静态ip并可访问网络-windows下的VMware