Skip to content

Commit

Permalink
Adding support for disable metrics. Useful for development
Browse files Browse the repository at this point in the history
  • Loading branch information
patoroco committed Jun 22, 2019
1 parent 106bfd8 commit 02e6943
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions django_statsd/settings.py
Expand Up @@ -21,6 +21,10 @@ def get_setting(key, default=None):
#: to DEBUG if not configured
STATSD_DEBUG = get_setting('STATSD_DEBUG', get_setting('DEBUG'))

#: Statsd disabled mode, avoids to send metrics to the real server.
#: Useful for debugging purposes.
STATSD_DISABLED = get_setting('STATSD_DISABLED', False)

#: Enable creating tags as well as the bare version. This causes an ajax view
#: to be stored both as the regular view name and as the ajax tag. Supported
#: separators are _is_ and =
Expand All @@ -35,5 +39,3 @@ def get_setting(key, default=None):
#: Statsd sample rate, lowering this decreases the (random) odds of actually
#: submitting the data. Between 0 and 1 where 1 means always
STATSD_SAMPLE_RATE = get_setting('STATSD_SAMPLE_RATE', 1.0)


7 changes: 5 additions & 2 deletions django_statsd/utils.py
Expand Up @@ -2,7 +2,7 @@
from . import settings


def get_connection(host=None, port=None, sample_rate=None):
def get_connection(host=None, port=None, sample_rate=None, disabled=None):
if not host:
host = settings.STATSD_HOST

Expand All @@ -12,7 +12,10 @@ def get_connection(host=None, port=None, sample_rate=None):
if not sample_rate:
sample_rate = settings.STATSD_SAMPLE_RATE

return statsd.Connection(host, port, sample_rate)
if not disabled:
disabled = settings.STATSD_DISABLED

return statsd.Connection(host, port, sample_rate, disabled)


def get_client(name, connection=None, class_=statsd.Client):
Expand Down

0 comments on commit 02e6943

Please sign in to comment.