This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from myoung34/datadog
Add datadog statsd emitter
- Loading branch information
Showing
10 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "Tilty" | ||
version = "0.0.1" | ||
version = "0.3.0" | ||
description = "A pluggable system to receive and transmit bluetooth events from the Tilt Hydrometer" | ||
authors = ["Marcus Young <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -12,6 +12,7 @@ pybluez = "^0.22.0" | |
requests = "^2.22" | ||
jinja2 = "^2.11.1" | ||
influxdb = "^5.2.3" | ||
datadog = "^0.34.1" | ||
|
||
[tool.poetry.dev-dependencies] | ||
flake8 = "^3.7" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
from unittest import mock | ||
|
||
from tilty.emitters import datadog | ||
|
||
|
||
@mock.patch('tilty.emitters.datadog.statsd') | ||
@mock.patch('tilty.emitters.datadog.initialize') | ||
def test_datadog( | ||
mock_statsd_init, | ||
mock_statsd_client, | ||
): | ||
config = { | ||
'host': 'http://statsd.google.com', | ||
'port': '8130', | ||
'temperature': '55', | ||
'gravity': '1054', | ||
'color': 'black', | ||
} | ||
datadog.Datadog(config=config).emit() | ||
mock_statsd_init.mock_calls == [ | ||
mock.call(statsd_host='http://statsd.google.com', statsd_port='8130') | ||
] | ||
assert mock_statsd_client.mock_calls == [ | ||
mock.call.gauge('tilty.temperature', '55', tags=['color:black']), | ||
mock.call.gauge('tilty.gravity', '1054', tags=['color:black']), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
""" DataDog emitter """ | ||
import logging | ||
|
||
from datadog import initialize, statsd | ||
|
||
from tilty.common import safe_get_key | ||
|
||
LOGGER = logging.getLogger() | ||
|
||
|
||
class Datadog: # pylint: disable=too-few-public-methods | ||
""" Class to represent the actual device """ | ||
def __init__(self, config): | ||
""" Initializer | ||
Args: | ||
config: (dict) represents the configuration for the emitter | ||
""" | ||
self.temperature = config['temperature'] | ||
self.gravity = config['gravity'] | ||
self.color = config['color'] | ||
options = { | ||
'statsd_host': config['host'], | ||
'statsd_port': safe_get_key(config, 'port', 8125), | ||
} | ||
initialize(**options) | ||
|
||
def emit(self, **kwargs): # pylint: disable=no-self-use,unused-argument | ||
""" Initializer | ||
Args: | ||
""" | ||
LOGGER.info('[datadog] posting temperature data') | ||
statsd.gauge( | ||
'tilty.temperature', | ||
self.temperature, | ||
tags=[f"color:{self.color}"] | ||
) | ||
LOGGER.info('[datadog] posting gravity data') | ||
statsd.gauge( | ||
'tilty.gravity', | ||
self.gravity, | ||
tags=[f"color:{self.color}"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters