We make quite a bit of use of Amazon SQS for some of critical applications at our setup and as per our monitoring requirements I wanted to make sure that we get SQS queue lengths being monitored through Nagios. I had earlier made use of boto library during one of our unsuccessful attempts at using Hadoop for some analytics project. However this time around I was able to make good use of boto libraries to get the count of messages in a SQS queue with just few lines of codes. Following is code snippet used to get count of number of messages in a SQS queue:import sys
from boto.sqs.connection import SQSConnection
conn=SQSConnection('AWS_ACCESS_KEY_ID','AWS_SECRET_KEY')
q=conn.get_queue(sys.argv[1])
attrib = q.get_attributes("ApproximateNumberOfMessages")
print int(attrib['ApproximateNumberOfMessages'])
In order to use the above code snippet, just follow following steps:
1. Install boto. To quickly setup boto, get latest boto source code from http://code.google.com/p/boto/. Extact the compressed file and do a python setup.py install as root.
2. Copy paste the above code to a temporary file say /tmp/test.py. Replace 'AWS_ACCESS_KEY_ID' and 'AWS_SECRET_KEY' with relevant details.
3. Execute the code snippet using : python test.py [SQS_QUEUE_NAME]
1 comments:
I would like to exchange links with your site techynfreesouls.blogspot.com
Is this possible?
Post a Comment