基于python的weblogic消息队列积压监控

Posted 电渠SRE互联网运维

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于python的weblogic消息队列积压监控相关的知识,希望对你有一定的参考价值。

# _*_ coding=utf-8 _*_

_author_ = 'cf'

_date_ = '2017/8/15 10:30'


import os

import sys

import json

import time

import ConfigParser


from selenium import webdriver

from bs4 import BeautifulSoup as bs



# reload(sys)

# sys.setdefaultencoding('utf-8')


# host = "http://10.243.30.15:7090"

# host = "127.0.0.1:17090"

config = ConfigParser.ConfigParser()

config.readfp(open("/ict/getDataFromWeblogic/ipconfig.ini", "rb"))

iplist = config.get("global", "ip").split("\n")


for ip in iplist:

    host = ip

    loginUrl = "http://" + host + ":9090/ztconsole/login/LoginForm.jsp"

    # 模拟登陆

    phan = webdriver.PhantomJS()

    phan.get(loginUrl)

    # login_content = phan.page_source


    # 输入用户名

    try:

        phan.find_element_by_xpath("//input[@id='j_username']").send_keys('weblogic')

        print 'input username success!'

    except:

        print 'input username error!'

    time.sleep(1)

    # 输入密码

    try:

        password = "Yang#tao@"+host.split(".")[3]

        phan.find_element_by_xpath("//input[@id='j_password']").send_keys(password)

        print 'input password success!'

    except:

        print 'input password error!'

    time.sleep(1)

    # 点击登录

    try:

        phan.find_element_by_xpath("//input[@class='formButton']").click()

        print 'click login success!'

    except:

        print 'click login error!'

    time.sleep(3)

    # 获取cookie

    cookies = phan.get_cookies()

    # print cookies

    # 将获取到的cookie加入phantomjs中

    for c in cookies:

        phan.add_cookie(c)

    # 获取当前页面url

    curpage_url = phan.current_url

    print curpage_url

    # 获取主页内容,爬取服务器列表页面URL

    phan.get(curpage_url)

    home_content = phan.page_source

    soup = bs(home_content, "html.parser")

    ahref = soup.find_all("a")

    serverTableUrl = "http://" + host + ":9090/ztconsole/console.portal?_nfpb=true&_pageLabel=CoreServerServerTablePage"

    # 获取服务器列表页面内容,爬取服务对应端口

    phan.get(serverTableUrl)

    serverTable_content = phan.page_source

    soup = bs(serverTable_content, "html.parser")


    trlist = []

    for tr in soup.find_all("tr",class_ = "rowEven"):

        trlist.append(tr)

    for tr in soup.find_all("tr",class_ = "rowOdd"):

        trlist.append(tr)

    # print trlist

    servers = []

    for tr in trlist:

        td = tr.find_all("td")

        server = []

        server.append(td[1].string)

        server.append(td[6].string)

        servers.append(server)



    # 获取服务的监视线程数的队列长度

    def getQueueLength(serverName):


        try:

            # threadsUrl = soup.find("a", title="监视 - 线程数- 选项卡").get("href")

            if "AdminServer" in serverName:

                serverName = "AdminServer"

            elif "adminServer" in serverName:

                serverName = "adminServer"

            threadsUrl = "http://" + host + ":9090/ztconsole/console.portal?_nfpb=true&_pageLabel=ServerMonitoringThreadsPage&handle=com.bea.console.handles.JMXHandle%28%22com.bea%3AName%3D"+serverName+"%2CType%3DServer%22%29"

            print threadsUrl

            phan.get(threadsUrl)

            threads_content = phan.page_source

            soup = bs(threads_content, "html.parser")

        except Exception:

            pass

        # print threads_content

        queueLength = soup.find("td", id="queueLength1").string

        print queueLength

        return queueLength

    # queueLength1 = getQueueLength(server1)

    # queueLength2 = getQueueLength(server2)

    for s in servers:

        s.append(getQueueLength(s[0]))



    def post_Data(data):

        data = json.dumps(data)

        print(data)

        os.system('''curl -X POST -d '%s' http://127.0.0.1:1988/v1/push''' % data)



    def main(endpoint, step, value, port):

        timestamp = int(time.time())

        datas = []


        i = {

            'metric': "queueLength",

            'endpoint': "ict_weblogic_"+endpoint,

            'timestamp': timestamp,

            'step': step,

            'value': int(value),

            'counterType': 'GAUGE',

            'tags': "port=%s" % port

        }

        datas.append(i)

        # print(datas)

        return datas




    if __name__ == '__main__':

        for server in servers:

            serverDate = main(host, 300, server[2], server[1])

            post_Data(serverDate)


# 关闭phantomjs

phan.quit()


以上是关于基于python的weblogic消息队列积压监控的主要内容,如果未能解决你的问题,请参考以下文章

三招!解决消息队列的数据积压问题

消息积压的处理

系统学习消息队列分享(八) 息积压了该如何处理?

消息队列消息积压了该如何处理

生产环境消息队列ActiveMQ的数据积压优化过程

消息队列漫谈:消息丢失,消息重复,消息积压一些处理方式