Skip to content

Commit

Permalink
fix local_settings.py (Sir Not-Appearing-In-This-Repo) and cleanup so…
Browse files Browse the repository at this point in the history
…me error handling
  • Loading branch information
Steve Ivy authored and kastner committed Feb 17, 2011
1 parent 623e026 commit 2e36c45
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions python_example.py
@@ -1,3 +1,13 @@
# python_example.py

# Steve Ivy <steveivy@gmail.com>
# http://monkinetic.com

# this file expects local_settings.py to be in the same dir, with statsd host and port information:
#
# statsd_host = 'localhost'
# statsd_port = 8125

# Sends statistics to the stats daemon over UDP
class Statsd(object):

Expand Down Expand Up @@ -25,16 +35,17 @@ def update_stats(stats, delta=1, sampleRate=1):
for stat in stats:
data[stat] = "%s|c" % delta

StatsD.send(data, sampleRate)
Statsd.send(data, sampleRate)

# Squirt the metrics over UDP
@staticmethod
def send(data, sample_rate=1):

try:
import local_settings as settings
host = settings['statsd_host']
port = settings['statsd_port']
host = settings.statsd_host
port = settings.statsd_port
addr=(host, port)
except Error:
exit(1)

Expand All @@ -54,7 +65,8 @@ def send(data, sample_rate=1):
value = data[stat]
send_data = "%s:%s" % (stat, value)
udp_sock.sendto(send_data, addr)
except Error, e:
except:
import sys
from pprint import pprint
pprint(e)
print "Unexpected error:", pprint(sys.exc_info())
pass # we don't care

0 comments on commit 2e36c45

Please sign in to comment.