Skip to content

Commit

Permalink
Add environment variable to disable statsd metric collection (#589)
Browse files Browse the repository at this point in the history
* Add variable to disable statsd

* Update docs

* Address review

* Fix style nit

Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>

Co-authored-by: Jiri Kuncar <jiri.kuncar@gmail.com>
  • Loading branch information
dgzlopes and jirikuncar authored Aug 6, 2020
1 parent 190ca57 commit 8ef25b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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 @@ -103,6 +103,9 @@ def __init__(
If set, it is appended to the constant (global) tags of the statsd client.
:type DD_VERSION: string
:envvar DD_DOGSTATSD_DISABLE: Disable any statsd metric collection (default False)
:type DD_DOGSTATSD_DISABLE: boolean
:param host: the host of the DogStatsd server.
:type host: string
Expand Down Expand Up @@ -157,6 +160,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_DISABLE') not in {'True', 'true', 'yes', '1'}:
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 @@ -445,6 +454,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

0 comments on commit 8ef25b7

Please sign in to comment.