• 使用python获得activemq信息(通过http://server:8161/


     1 # encoding=utf-8
     2 import urllib2
     3 import cookielib
     4 # from BeautifulSoup import BeautifulSoup
     5 from bs4 import BeautifulSoup
     6 import re
     7 queue_url = "http://192.168.16.218:8161/admin/queues.jsp"
     8 
     9 def MQBrowser(url):
    10     login_page = queue_url
    11 
    12     try:
    13         cj = cookielib.CookieJar()
    14         opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    15 
    16         opener.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'),
    17                              ('Authorization', 'Basic YWRtaW46YWRtaW4=')]
    18 
    19         opener.open(url)
    20         op = opener.open(login_page)
    21         data = op.read()
    22         return data
    23     except Exception, e:
    24         print str(e)
    25 
    26 
    27 def get_queue_size_by_name(queue_name):
    28     content = MQBrowser(queue_url)
    29     soup = BeautifulSoup(''.join(content))
    30     queue_list = soup.findAll('tbody')[1].findAll('tr')
    31     for i in queue_list:
    32         queue_info = i.findAll('td')
    33         if queue_name == queue_info[0].text.strip():
    34             num_pending = queue_info[1].text.strip()
    35             return num_pending
    36     return -1
    37 
    38 
    39 def get_queue_size():
    40     content = MQBrowser(queue_url)
    41     soup = BeautifulSoup(''.join(content))
    42     queue_list = soup.findAll('tbody')[1].findAll('tr')
    43     queue_dic = {}
    44     for i in queue_list:
    45         queue_info = i.findAll('td')
    46         queue_name = queue_info[0].text.strip()
    47         num_pending = queue_info[1].text.strip()
    48         num_consumer = queue_info[2].text.strip()
    49         num_enqueued = queue_info[3].text.strip()
    50         num_dequeued = queue_info[4].text.strip()
    51         queue_dic[queue_name] = [num_pending, num_consumer, num_enqueued, num_dequeued]
    52     return queue_dic
    53 
    54 
    55 def get_queue_detail(queue_name):
    56     content = MQBrowser("http://127.0.0.1:8161/admin/browse.jsp?JMSDestination=%s" % queue_name)
    57     soup = BeautifulSoup(''.join(content))
    58 
    59 
    60 if __name__ == "__main__":
    61     import sys
    62 
    63     if len(sys.argv) == 2:
    64         queue_name = sys.argv[1]
    65     else:
    66         queue_name = "None"
    67         # print get_queue_size_by_name(queue_name)
  • 相关阅读:
    ubuntu 12.04安装redis2.6.16
    linux常用命令(自我积累)-two
    计算机历年考研复试上机基础题(一)
    PhantomJS爬虫 -----全国高校查询-------计算机科学与技术前50大学
    python3爬虫 -----爬取大学信息并通过matplotlib与numpy绘制结果-----from最好大学网
    51Nod 1265 四点共面
    算法训练 出现次数最多的整数
    51nod 1101 换零钱 (完全背包)
    Poj3624 Charm Bracelet (01背包)
    Poj1258 Agri-Net (最小生成树 Prim算法 模板题)
  • 原文地址:https://www.cnblogs.com/yeyong/p/3960550.html
Copyright © 2020-2023  润新知