Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for disable metrics #16

Merged
merged 2 commits into from Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion 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 @@ -39,4 +43,4 @@ def get_setting(key, default=None):
#: List of regexp to ignore views.
STATSD_VIEWS_TO_SKIP = get_setting('STATSD_VIEWS_TO_SKIP', [
r'django.contrib.admin',
])
])
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