设为首页 收藏本站
查看: 2422|回复: 0

[经验分享] 使用python脚本监控weblogic

[复制链接]

尚未签到

发表于 2017-2-18 11:13:12 | 显示全部楼层 |阅读模式
  1.python的脚本如下:


DSC0000.gif DSC0001.gif


  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都是找出最大值即可
  至此,监控过程全部完成。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-343812-1-1.html 上篇帖子: 我遇到的weblogic安装部署和连接池中的错误 和解决办法 下篇帖子: WebLogic Server 管理最佳实践
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表