Python查看MQ队列深度

分享一段代码,很简单但是也很实用。

 1 #!/usr/bin/python
 2 #-*- coding:gb18030 -*-
 3 '''
 4   Usage: mq.py [Qmgr]
 5         *get the queues' curdepth which type is local,
 6          and sorted by curdepth desc.
 7   Auth : nextgodhand@163.com
 8 '''
 9 
10 import re
11 import os
12 import sys
13 
14 if __name__=='__main__':
15         if len(sys.argv)!=2:
16                 print 'Usage: %s [Qmgr]' % sys.argv[0]
17                 sys.exit(1)
18         Qmgr=sys.argv[1]
19 
20         text=os.popen("echo 'DIS QUEUE(*) CURDEPTH QTYPE(QLOCAL)'|runmqsc %s" % Qmgr).read()
21         queues=re.findall(r'QUEUE(([^*]*?))', text)
22         if not queues:
23                 print 'MQ: QueueManager [%s] not exist' % Qmgr
24                 sys.exit(2)
25         depths=re.findall(r'CURDEPTH(([^*]*?))', text)
26         qdlist=sorted(zip(queues, depths), cmp=lambda x, y: cmp(int(y[1]), int(x[1])))
27 
28         print '% 40s, %s' % ('QueueName', 'CurrentDepth')
29         for qd in qdlist:
30                 print '% 40s, %s' % (qd[0], qd[1])

贴张图,看看效果:

原文地址:https://www.cnblogs.com/lichmama/p/3835255.html