better error handling in statsd backend

This commit is contained in:
Tim Daly, Jr
2013-04-22 20:47:38 +00:00
parent 36f729d795
commit 88a64b83e9
2 changed files with 5 additions and 5 deletions

View File

@@ -27,7 +27,6 @@ def _initLogging(logging, sys):
if logger.level == logging.NOTSET:
logger.setLevel(logging.INFO)
if not logger.handlers:
print "yadda"
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s %(name)s %(message)s'))

View File

@@ -29,9 +29,12 @@ def send(span):
def statsd_send(name, value, units):
stat = str(name).replace(' ', '-') + ':' + str(int(value)) + '|' + str(units)
#logger.info('sending stat {0}'.format(stat))
with lock:
udp_socket.sendto(stat, (hostname_cache.get(config.statsd_host), config.statsd_port))
try:
udp_socket.sendto(stat, (hostname_cache.get(config.statsd_host), config.statsd_port))
except Exception:
if config.debug:
logger.warning("Error sending metric to statsd.", exc_info=True)
def server_name(note):
address = note.address.replace('.', '-')
@@ -46,6 +49,4 @@ def send(span):
# a count stat for each note
for note in span.notes:
stat_name = server_name(note) + '.' + span.name + '.' + str(note.value)
#print "before"
statsd_send(stat_name, 1, 'c')
#print "after"