Monitoring SQS metrics with Amazon CloudWatch
Learn how to use Amazon CloudWatch to monitor and access metrics for a Simple Queue Service.
Amazon CloudWatch is a helpful, free tool for developers who want to monitor metrics for a Simple Queue Service (SQS) and trigger an alarm when a threshold is met. The metrics you configure for the queue are automatically collected and pushed to CloudWatch every five minutes -- up to a six-hour period. It offers more than Amazon Simple Notification Service (SNS) which only sends email notification but does not monitor metrics.
For example, you can monitor the NumberOfEmptyReceives metric for a queue to make sure that your application isn't spending too much of its time polling for new messages. You can set an alarm to send you an email notification if a threshold is met for the NumberOfMessagesReceived metric.
Accessing CloudWatch metrics
You can access metrics to monitor how the messages are behaving in an existing queue.
- Sign in to the AWS Management Console.
- Open the Amazon CloudWatch console.
- In the right navigation bar, select a region you signed up for.
- Under Metrics in the left navigation pane, select SQS. In the dialog, the Metric Name column shows the available metrics for each queue.
- Select a queue for which you want to view metrics.
- Click on the metric for the selected queue to get more details. The metrics can be one of the following:
Setting CloudWatch alarms
You can use CloudWatch to set alarms on CloudWatch when a threshold is met for a metric. For example, when you set an alarm for the NumberOfEmptyReceives metric, you will get an email notifying you that a threshold number is met.
- Sign in to the AWS Management Console.
- Open the Amazon CloudWatch console.
- In the left navigation pane, select Alarms.
- Click Create Alarm.
- In the Create Alarm wizard, scroll through the Amazon SQS metrics to locate the metric you would like to monitor with an alarm.
- Select the metric and then click Next.
Under Alarm Threshold:
- In the Name and Description boxes, enter values.
- Set Whenever: [metric] in first field to an equality sign (>=) from the drop down list and then a value greater than zero, and second field to a value of consecutive period(s), as shown in the following example.
To define what Actions to take when your alarm changes state, choose State is ALARM. This means an alarm is triggered whenever the metric is outside the defined threshold.
Do not choose State is OK, that indicates the metric is within the threshold, or State is INSUFFICIENT DATA, that indicates the alarm has just started but the metric is not available.
If you want CloudWatch to send you an email when the alarm state is triggered, you can either select a preexisting Amazon SNS or click the new list link.
If you go for the second option, you can:
- Enter a value (NewNotification) for a new email topic.
- Enter email addresses, each separated with a comma.
- Click Create Alarm.
The Confirm email addresses dialog requires that all email addresses in the list must be confirmed to indicate that the recipients are willing to receive notifications to their email addresses.
Get documentation on the following services from Amazon
How to monitor metrics
If you've used a personal email address, the dialog asks you to check your email inbox for a message with the subject "AWS Notification – Subscription Confirmation."
The email will notify you that you've subscribed to a topic, for example:
arn:aws:sns:us-east-1:14901835636:NewNotification
Click the link and then Yes to confirm.
Select View Alarm after the dialog receives your confirmation.
The list is saved and will appear in the drop-down menu for future alarms.
You have 72 hours to receive confirmation from all recipients of email addresses.
In conclusion, CloudWatch is a handy tool to monitor metrics on SQS queues.