diff --git a/examples/python_example.py b/examples/python_example.py index 7869ec2..b2f39c8 100644 --- a/examples/python_example.py +++ b/examples/python_example.py @@ -2,15 +2,15 @@ # Steve Ivy # 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): - + @staticmethod def timing(stat, time, sample_rate=1): """ @@ -38,7 +38,7 @@ class Statsd(object): >>> Statsd.decrement('some.int') """ Statsd.update_stats(stats, -1, sample_rate) - + @staticmethod def update_stats(stats, delta=1, sampleRate=1): """ @@ -52,7 +52,7 @@ class Statsd(object): data[stat] = "%s|c" % delta Statsd.send(data, sampleRate) - + @staticmethod def send(data, sample_rate=1): """ @@ -65,9 +65,9 @@ class Statsd(object): addr=(host, port) except: exit(1) - + sampled_data = {} - + if(sample_rate < 1): import random if random.random() <= sample_rate: @@ -76,8 +76,8 @@ class Statsd(object): sampled_data[stat] = "%s|@%s" %(value, sample_rate) else: sampled_data=data - - from socket import * + + from socket import socket, AF_INET, SOCK_DGRAM udp_sock = socket(AF_INET, SOCK_DGRAM) try: for stat in sampled_data.keys():