• 使用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 = "
    "
     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:weblogiceawlserver_10.3commonin下
    3.修改collectionRuntime.py中的weblogic的用户名,密码,IP,端口,日志路径修改成正确的数据。

    4.打开CMD窗口,切换到D:weblogiceawlserver_10.3commonin下,然后执行命令wlst.cmd CollectRuntime.py

    5.在日志路径下会看到自动生成的CSV文件。能看到HoggingThread和busyThread的数据。

    监控gc执行情况的方法如下:

    1. 首先需要安装jdk,在jdk/bin目录下,例如:C:Program Files (x86)Javajdk1.6.0_10in

    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都是找出最大值即可

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

  • 相关阅读:
    Https、SSL/TLS相关知识及wireShark抓包分析
    谷歌浏览器如何查看当前网页使用哪个TLS版本?
    centos7 ssh启动异常时,用ssh -t 查看报错信息。
    centos7设置久静态ip
    将cmder.exe添加到右键菜单,并配置环境变量
    KeepAlive与KeepAlive的区别
    openssl笔记
    1.javascript知识点总结
    js的小练习
    7.利用canvas和js画一个渐变的
  • 原文地址:https://www.cnblogs.com/villadom/p/3967870.html
Copyright © 2020-2023  润新知