码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-09-07 17:09:05      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   使用   ar   for   

 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)

 

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

标签:des   style   blog   http   color   io   使用   ar   for   

原文地址:http://www.cnblogs.com/yeyong/p/3960550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!