Skip to content

Commit

Permalink
Merge pull request statsd#151 from alfredodeza/master
Browse files Browse the repository at this point in the history
Fixes some errors
  • Loading branch information
mrtazz committed Sep 1, 2012
2 parents 4bd7597 + 7f38eee commit 0b39c18
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions examples/python_example.py
Expand Up @@ -2,15 +2,15 @@

# 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):

@staticmethod
def timing(stat, time, sample_rate=1):
"""
Expand Down Expand Up @@ -38,7 +38,7 @@ def decrement(stats, sample_rate=1):
>>> Statsd.decrement('some.int')
"""
Statsd.update_stats(stats, -1, sample_rate)

@staticmethod
def update_stats(stats, delta=1, sampleRate=1):
"""
Expand All @@ -52,7 +52,7 @@ def update_stats(stats, delta=1, sampleRate=1):
data[stat] = "%s|c" % delta

Statsd.send(data, sampleRate)

@staticmethod
def send(data, sample_rate=1):
"""
Expand All @@ -63,11 +63,11 @@ def send(data, sample_rate=1):
host = settings.statsd_host
port = settings.statsd_port
addr=(host, port)
except Error:
except:
exit(1)

sampled_data = {}

if(sample_rate < 1):
import random
if random.random() <= sample_rate:
Expand All @@ -76,8 +76,8 @@ def send(data, sample_rate=1):
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():
Expand All @@ -88,4 +88,4 @@ def send(data, sample_rate=1):
import sys
from pprint import pprint
print "Unexpected error:", pprint(sys.exc_info())
pass # we don't care
pass # we don't care

0 comments on commit 0b39c18

Please sign in to comment.