Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Last active August 18, 2018 12:02
Show Gist options
  • Save tuxfight3r/4ece17447681cf1de335 to your computer and use it in GitHub Desktop.
Save tuxfight3r/4ece17447681cf1de335 to your computer and use it in GitHub Desktop.
python script to parse activemq queue
#!/usr/bin/python
#Purpose: To list activemq queues in readable format
#Date: 27/11/2015
#Author: Mohan
import calendar
import sys
import time
import os
from xml.dom.minidom import parse,parseString
import urllib2
"""
set the mode for level of detail/format to be printed
FULL - QUEUE_NAME consumers:value1 queuesize:value2 enqcount:value3 deqcount:value4
INFO - QUEUE_NAME consumers:value1 queuesize:value2
CSV - QUEUE_NAME,value1,value2,value3,value4
"""
#mode=""
mode="FULL"
if len(sys.argv) < 2:
base_name=os.path.basename(__file__)
print """
Usage: ./%s <activemq_host_ip>
Example: ./%s 192.168.0.1
""" % (base_name, base_name)
sys.exit(0)
else:
host_ip=sys.argv[1]
#url='http://'+host_ip+':8161/admin/xml/queues.jsp'
url='http://'+host_ip+':8161/amq.xml'
#url="file:///home/mohan/amq.xml"
print "URL:" , url
try:
dom=parse(urllib2.urlopen(url))
except:
print "Error connecting to activemq, stopping."
sys.exit(2)
for node in dom.getElementsByTagName('queue'):
con_count= int(node.childNodes[1].getAttribute('consumerCount'))
enq_count= int(node.childNodes[1].getAttribute('enqueueCount'))
deq_count= int(node.childNodes[1].getAttribute('dequeueCount'))
queue_size= int(node.childNodes[1].getAttribute('size'))
queue_name= str(node.getAttribute('name'))
if mode=="FULL":
print "%-30s consumers:%-7d queuesize:%-7d enqcount:%-7d deqcount:%-7d" % (queue_name,con_count,queue_size,enq_count,deq_count)
elif mode=="CSV":
print queue_name,con_count,queue_size,enq_count,deq_count
else:
print "%-30s consumers:%-7d queuesize:%-7d" % (queue_name,con_count,queue_size)
@arunkumargujjar
Copy link

Hi if i run the same code on my local machine it is throwing an error output as
HTTP Error 401: Unauthorized
can you help me out in solving the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment