首页 > 代码库 > 使用python获得activemq信息(通过http://server:8161/

使用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_url11 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 =http://www.mamicode.com/ op.read()22         return data23     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_pending36     return -137 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_dic53 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 sys62 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)

 

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