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

Add environment variable to disable statsd metric collection #589

Merged
merged 7 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ tags = ['version:1', 'application:web']
api.Event.create(title=title, text=text, tags=tags)
```

In development, you can disable any `statsd` metric collection using `DD_DOGSTATSD_DISABLE=True` (or any not-empty value).

## DogStatsD

In order to use DogStatsD metrics, the Agent must be [running and available](https://docs.datadoghq.com/developers/dogstatsd/?tab=python).
Expand Down
12 changes: 12 additions & 0 deletions datadog/dogstatsd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def __init__(
If set, it is appended to the constant (global) tags of the statsd client.
:type DD_VERSION: string

:envvar DD_DOGSTATSD_ENABLE: Enable any statsd metric collection (default True)
:type DD_DOGSTATSD_ENABLE: boolean
dgzlopes marked this conversation as resolved.
Show resolved Hide resolved

:param host: the host of the DogStatsd server.
:type host: string

Expand Down Expand Up @@ -154,6 +157,12 @@ def __init__(
log.warning("Port number provided in DD_DOGSTATSD_PORT env var is not an integer: \
%s, using %s as port number", dogstatsd_port, port)

# Check enabled
if os.environ.get('DD_DOGSTATSD_ENABLE', 'True') in {'True', 'true', 'yes', '1'}:
dgzlopes marked this conversation as resolved.
Show resolved Hide resolved
self._enabled = True
else:
self._enabled = False

# Connection
self._max_payload_size = max_buffer_len
if socket_path is not None:
Expand Down Expand Up @@ -412,6 +421,9 @@ def _report(self, metric, metric_type, value, tags, sample_rate):
"""
if value is None:
return

if self._enabled is not True:
return

if self._telemetry:
self.metrics_count += 1
Expand Down