Python查看MQ队列深度

时间:2022-09-10 16:01:01

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

 #!/usr/bin/python
#-*- coding:gb18030 -*-
'''
Usage: mq.py [Qmgr]
*get the queues' curdepth which type is local,
and sorted by curdepth desc.
Auth : nextgodhand@163.com
''' import re
import os
import sys if __name__=='__main__':
if len(sys.argv)!=2:
print 'Usage: %s [Qmgr]' % sys.argv[0]
sys.exit(1)
Qmgr=sys.argv[1] text=os.popen("echo 'DIS QUEUE(*) CURDEPTH QTYPE(QLOCAL)'|runmqsc %s" % Qmgr).read()
queues=re.findall(r'QUEUE\(([^*]*?)\)', text)
if not queues:
print 'MQ: QueueManager [%s] not exist' % Qmgr
sys.exit(2)
depths=re.findall(r'CURDEPTH\(([^*]*?)\)', text)
qdlist=sorted(zip(queues, depths), cmp=lambda x, y: cmp(int(y[1]), int(x[1]))) print '% 40s, %s' % ('QueueName', 'CurrentDepth')
for qd in qdlist:
print '% 40s, %s' % (qd[0], qd[1])

贴张图,看看效果:

Python查看MQ队列深度