0

At the moment we use the package boto to get queue messages and then, do some processing. The relevant code is:

from boto.sqs.message import RawMessage
import boto.sqs
import boto.sns
import json

conn = boto.sqs.connect_to_region(
    "us-west-1",
    aws_access_key_id="XXXXXXX",
    aws_secret_access_key="XXXXXXX")
q=conn.get_queue('queueName')
q.set_message_class(RawMessage)
res=q.get_messages(10,wait_time_seconds=1)
....

and the rest is just processing code (not important for the question). This code works perfectly.

I was wondering if there is a way to, from python, get the metrics of the queue, for example, NumberOfMessagesSent.

Based on this post get metrics and the CloudWatch website, I thought there might be something like

conn = boto.sqs.cloudwatch.connect_to_region()

from which I could do

conn.get_metric_statistics()

but it does not seem to be the case (unless I have missed something).

I have found this very nice piece of code. But I was wondering if there is something "better" (or a more concise alternative) within boto.sqs

Community
  • 1
  • 1
Javier
  • 1,530
  • 4
  • 21
  • 48

2 Answers2

1

You can get the following attributes if you call q.get_attributes()

ApproximateNumberOfMessages, ApproximateNumberOfMessagesNotVisible, VisibilityTimeout, CreatedTimestamp, LastModifiedTimestamp, Policy ReceiveMessageWaitTimeSeconds

For things like NumberOfMessagesSent you will need to query CloudWatch for the data SQS logs there. The code you linked looks like the proper way to query CloudWatch metrics using boto.

Mark B
  • 183,023
  • 24
  • 297
  • 295
0

Thanks,

Also, in case anyone finds it useful, we found a similar way to the one in the code I linked, but perhaps a little bit more concise.

import boto
import datetime
conn = boto.connect_cloudwatch(aws_access_key_id="xxx",aws_secret_access_key="xxx")
conn.get_metric_statistics(
        300,
        datetime.datetime.utcnow() - datetime.timedelta(seconds=300),
        datetime.datetime.utcnow(),
        'ApproximateNumberOfMessagesVisible',
        'AWS/SQS',
        'Average',
        dimensions={'QueueName':['Myqueuename']}
   )
Javier
  • 1,530
  • 4
  • 21
  • 48