mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-21 19:28:34 +00:00
Remove prepending host name
This commit is contained in:
parent
1fb1f46bc1
commit
6d98e9b806
3 changed files with 11 additions and 22 deletions
|
@ -54,7 +54,6 @@ Settings
|
|||
:port: The Statsd port
|
||||
:prepend_metric_type: Optional flag to prepend bucket path with the StatsD
|
||||
metric type
|
||||
:prepend_hostname: Optional flag to prepend bucket path with the hostname
|
||||
|
||||
InfluxDB Mixin
|
||||
--------------
|
||||
|
|
|
@ -120,20 +120,17 @@ class StatsDCollector(object):
|
|||
:param str namespace: The StatsD bucket to write metrics into.
|
||||
:param bool prepend_metric_type: Optional flag to prepend bucket path
|
||||
with the StatsD metric type
|
||||
:param bool prepend_hostname: Optional flag to prepend bucket path with
|
||||
the hostname
|
||||
|
||||
"""
|
||||
METRIC_TYPES = {'c': 'counters',
|
||||
'ms': 'timers'}
|
||||
|
||||
def __init__(self, host, port, namespace='sprockets',
|
||||
prepend_metric_type=True, prepend_hostname=True):
|
||||
prepend_metric_type=True):
|
||||
self._host = host
|
||||
self._port = int(port)
|
||||
self._namespace = namespace
|
||||
self._prepend_metric_type = prepend_metric_type
|
||||
self._prepend_hostname = prepend_hostname
|
||||
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
|
||||
|
||||
def send(self, path, value, metric_type):
|
||||
|
@ -169,8 +166,7 @@ class StatsDCollector(object):
|
|||
"""Get prefixes where applicable
|
||||
|
||||
Add metric prefix counters, timers respectively if
|
||||
:attr:`prepend_metric_type` flag is True. Adds hostname prefix
|
||||
if :attr:`prepend_hostname` is true.
|
||||
:attr:`prepend_metric_type` flag is True.
|
||||
|
||||
:param str metric_type: The metric type
|
||||
:rtype: list
|
||||
|
@ -179,8 +175,6 @@ class StatsDCollector(object):
|
|||
prefixes = []
|
||||
if self._prepend_metric_type:
|
||||
prefixes.append(self.METRIC_TYPES[metric_type])
|
||||
if self._prepend_hostname:
|
||||
prefixes.append(socket.gethostname())
|
||||
return prefixes
|
||||
|
||||
|
||||
|
@ -191,8 +185,8 @@ def install(application, **kwargs):
|
|||
install the collector into.
|
||||
:param kwargs: keyword parameters to pass to the
|
||||
:class:`StatsDCollector` initializer.
|
||||
:returns: :data:`True` if the client was installed by this call
|
||||
and :data:`False` otherwise.
|
||||
:returns: :data:`True` if the client was installed successfully,
|
||||
or :data:`False` otherwise.
|
||||
|
||||
- **host** The StatsD host. If host is not specified, the
|
||||
``STATSD_HOST`` environment variable, or default `127.0.0.1`,
|
||||
|
|
18
tests.py
18
tests.py
|
@ -49,7 +49,8 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
self.statsd = FakeStatsdServer(self.io_loop)
|
||||
statsd.install(self.application, **{'namespace': 'testing',
|
||||
'host': self.statsd.sockaddr[0],
|
||||
'port': self.statsd.sockaddr[1]})
|
||||
'port': self.statsd.sockaddr[1],
|
||||
'prepend_metric_type': True})
|
||||
|
||||
def tearDown(self):
|
||||
self.statsd.close()
|
||||
|
@ -59,8 +60,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
response = self.fetch('/')
|
||||
self.assertEqual(response.code, 204)
|
||||
|
||||
expected = 'testing.timers.{}.SimpleHandler.GET.204'.format(
|
||||
socket.gethostname().replace('.', '-'))
|
||||
expected = 'testing.timers.SimpleHandler.GET.204'
|
||||
for path, value, stat_type in self.statsd.find_metrics(expected, 'ms'):
|
||||
assert_between(250.0, float(value), 500.0)
|
||||
|
||||
|
@ -68,8 +68,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
response = self.fetch('/', method='POST', body='')
|
||||
self.assertEqual(response.code, 204)
|
||||
|
||||
prefix = 'testing.counters.{}.request.path'.format(
|
||||
socket.gethostname().replace('.', '-'))
|
||||
prefix = 'testing.counters.request.path'
|
||||
for path, value, stat_type in self.statsd.find_metrics(prefix, 'c'):
|
||||
self.assertEqual(int(value), 1)
|
||||
|
||||
|
@ -77,8 +76,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
response = self.fetch('/counters/path/5', method='POST', body='')
|
||||
self.assertEqual(response.code, 204)
|
||||
|
||||
prefix = 'testing.counters.{}.path'.format(
|
||||
socket.gethostname().replace('.', '-'))
|
||||
prefix = 'testing.counters.path'
|
||||
for path, value, stat_type in self.statsd.find_metrics(prefix, 'c'):
|
||||
self.assertEqual(int(value), 5)
|
||||
|
||||
|
@ -86,8 +84,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
response = self.fetch('/counters/one.two.three/0.25')
|
||||
self.assertEqual(response.code, 204)
|
||||
|
||||
prefix = 'testing.timers.{}.one.two.three'.format(
|
||||
socket.gethostname().replace('.', '-'))
|
||||
prefix = 'testing.timers.one.two.three'
|
||||
for path, value, stat_type in self.statsd.find_metrics(prefix, 'ms'):
|
||||
assert_between(250.0, float(value), 300.0)
|
||||
|
||||
|
@ -114,8 +111,7 @@ class StatsdConfigurationTests(testing.AsyncHTTPTestCase):
|
|||
statsd.install(self.application, **{'namespace': 'testing',
|
||||
'host': self.statsd.sockaddr[0],
|
||||
'port': self.statsd.sockaddr[1],
|
||||
'prepend_metric_type': False,
|
||||
'prepend_hostname': False})
|
||||
'prepend_metric_type': False})
|
||||
|
||||
def tearDown(self):
|
||||
self.statsd.close()
|
||||
|
|
Loading…
Reference in a new issue