-
Notifications
You must be signed in to change notification settings - Fork 31
/
sqs.py
executable file
·55 lines (46 loc) · 1.53 KB
/
sqs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
"""
Count the approximate number of messaages in your Amazon SQS queue(s).
Requires the boto python library (http://code.google.com/p/boto/).
Set the aws_key and aws_secret values before using the plugin.
Usage:
sqs.py [minimum_count] [maximum_count]
LICENSE: http://www.opensource.org/licenses/mit-license.php
AUTHOR: Caleb Groom <http://github.com/calebgroom>
"""
from boto.sqs.connection import SQSConnection
from boto.exception import SQSError
import sys
MAX_MESSAGES = 100
MIN_MESSAGES = 0
aws_key = ''
aws_secret = ''
# The alerting thresholds can be overridden via command line arguments
limits = [MIN_MESSAGES, MAX_MESSAGES]
for i in [2,3]:
if len(sys.argv) >= i:
try:
limits[i-2] = int(sys.argv[i-1])
except ValueError:
print 'status err argument "%s" is not a valid integer' % sys.argv[i-1]
sys.exit(1)
try:
conn = SQSConnection(aws_key, aws_secret)
queues = conn.get_all_queues()
error_queues = []
total = 0
for queue in queues:
count = queue.count()
total += count
if count < limits[0] or count > limits[1]:
error_queues.append(queue.name)
print 'metric %s int %d' % (queue.name, count)
if len(error_queues) == 0:
print 'status ok %d messages in all queues' % total
else:
s = '/'.join(error_queues)
print 'status err %s contains an unexpected number of messages' % s
except SQSError as e:
print 'status err SQS error:', e.reason
except:
print 'status err Unhandled error'