Source code for django_statsd.utils
import statsd
from . import settings
[docs]def get_connection(host=None, port=None, sample_rate=None):
if not host:
host = settings.STATSD_HOST
if not port:
port = settings.STATSD_PORT
if not sample_rate:
sample_rate = settings.STATSD_SAMPLE_RATE
return statsd.Connection(host, port, sample_rate)
[docs]def get_client(name, connection=None, class_=statsd.Client):
if not connection:
connection = get_connection()
return class_(name, connection)
[docs]def get_timer(name, connection=None):
return get_client(name, connection, statsd.Timer)
[docs]def get_counter(name, connection=None):
return get_client(name, connection, statsd.Counter)