Skip to content

Commit

Permalink
Update examples/python_example.py
Browse files Browse the repository at this point in the history
Give sample client a proper initializer, and give it a basic example 
metric to run if the script is called itself.
  • Loading branch information
sivy committed Nov 12, 2012
1 parent 4cf1e6d commit d9ecb0a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion examples/python_example.py
Expand Up @@ -11,6 +11,17 @@
# Sends statistics to the stats daemon over UDP
class Statsd(object):

def __init__(self, host=localhost, port=8125):
self.host = host
self.port = port
try:
import local_settings as settings
self.host = settings.statsd_host
self.port = settings.statsd_port
except:
pass
self.addr=(host, port)

@staticmethod
def timing(stat, time, sample_rate=1):
"""
Expand Down Expand Up @@ -83,9 +94,14 @@ def send(data, sample_rate=1):
for stat in sampled_data.keys():
value = sampled_data[stat]
send_data = "%s:%s" % (stat, value)
udp_sock.sendto(send_data, addr)
udp_sock.sendto(send_data, self.addr)
except:
import sys
from pprint import pprint
print "Unexpected error:", pprint(sys.exc_info())
pass # we don't care


if __name__=="__main__":
c = StatsdClient()
c.increment('example.python')

0 comments on commit d9ecb0a

Please sign in to comment.