Don't enable the metric queue if there's no Cloudwatch
This commit is contained in:
parent
b483209862
commit
f043bc1379
3 changed files with 15 additions and 4 deletions
|
@ -7,7 +7,7 @@ from threading import Thread
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def send_cloudwatch(metrics, app):
|
||||
def start_cloudwatch_sender(metrics, app):
|
||||
"""
|
||||
Starts sending from metrics to a new CloudWatchSender.
|
||||
"""
|
||||
|
@ -37,6 +37,7 @@ class CloudWatchSender(Thread):
|
|||
connection = boto.connect_cloudwatch(self._aws_access_key, self._aws_secret_key)
|
||||
except:
|
||||
logger.exception('Failed to connect to CloudWatch.')
|
||||
self._metrics.enable()
|
||||
|
||||
while True:
|
||||
put_metric_args, kwargs = self._metrics.get()
|
||||
|
|
|
@ -11,9 +11,15 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
class MetricQueue(object):
|
||||
def __init__(self):
|
||||
self._queue = Queue(10000)
|
||||
self._queue = None
|
||||
|
||||
def enable(self, maxsize=10000):
|
||||
self._queue = Queue(maxsize)
|
||||
|
||||
def put(self, *args, **kwargs):
|
||||
if self._queue is None:
|
||||
logging.debug('No metric queue: %s %s' %args, kwargs)
|
||||
return
|
||||
try:
|
||||
self._queue.put_nowait((args, kwargs))
|
||||
except Full:
|
||||
|
|
Reference in a new issue