Permalink
Browse files

fix local_settings.py (Sir Not-Appearing-In-This-Repo) and cleanup so…

…me error handling
  • Loading branch information...
1 parent 623e026 commit 2e36c455bbb7e4016c03fd74f85461eada05a70f Steve Ivy committed with kastner Feb 16, 2011
Showing with 17 additions and 5 deletions.
  1. +17 −5 python_example.py
View
@@ -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):
@@ -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)
@@ -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.