зеркало из https://github.com/microsoft/statsd.git
import * raises errors in Python 2.7
This commit is contained in:
Родитель
f43d8304b9
Коммит
7f38eee38c
|
@ -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):
|
||||
"""
|
||||
|
@ -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():
|
||||
|
|
Загрузка…
Ссылка в новой задаче