summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Socol <me@jamessocol.com>2013-07-27 22:40:28 +0000
committerJames Socol <me@jamessocol.com>2013-07-27 22:40:28 +0000
commit54a49d0fbc0842d6f9a57e82fff1b3c30f608a0c (patch)
tree893bb23c946af3bd690034d9fd468878a0d8b761
parentc1736e9ba93e5ebdf256e31eb73aafcb00808815 (diff)
downloadpystatsd-54a49d0fbc0842d6f9a57e82fff1b3c30f608a0c.tar.gz
Revert "Added suffix parameter"
This reverts commit 3c4ec687273416b355c20282e33249d87cd84b52. Given graphite's support for wildcards anywhere in the chain, this is an unnecessary complication. The same thing can be achieved with the prefix, e.g.: >>> import socket; >>> host, _, _ = socket.gethostname().partition('.') >>> prefix = 'my_app.' + host >>> client = StatsClient(prefix=prefix) Stats can be accessed in aggregate as 'stats.my_app.*.whatever.stat'.
-rw-r--r--docs/configure.rst17
-rw-r--r--docs/index.rst6
-rw-r--r--docs/reference.rst4
-rw-r--r--statsd/__init__.py6
-rw-r--r--statsd/client.py7
-rw-r--r--statsd/tests.py18
6 files changed, 10 insertions, 48 deletions
diff --git a/docs/configure.rst b/docs/configure.rst
index ae57c0b..de95fbe 100644
--- a/docs/configure.rst
+++ b/docs/configure.rst
@@ -26,8 +26,7 @@ They, and their defaults, are::
statsd = StatsClient(host='localhost',
port=8125,
- prefix=None,
- suffix=None)
+ prefix=None)
``host`` is the host running the statsd server. It will support any kind
of name or IP address you might use.
@@ -51,19 +50,6 @@ will produce two different stats, ``foo.baz`` and ``bar.baz``. Without
the ``prefix`` argument, or with the same ``prefix``, two
``StatsClient`` instances will update the same stats.
-``suffix`` can also be used to distinguish between hosts or environments.
-The suffix will be appended to all stats, automatically. This is useful
-when working with clusters consisting of multiple hosts. For example::
-
- from statsd import StatsClient
- from os import uname
-
- myhostname = uname()[1].split(".")[0]
- stats = StatsClient(suffix=myhostname)
-
-will append ``.hostname`` to all stats sent to statsd. Without this, all
-hosts in a cluster would update the same stats.
-
In Django
=========
@@ -77,7 +63,6 @@ Here are the settings and their defaults::
STATSD_HOST = 'localhost'
STATSD_PORT = 8125
STATSD_PREFIX = None
- STATSD_SUFFIX = None
You can use the default ``StatsClient`` simply::
diff --git a/docs/index.rst b/docs/index.rst
index 5e3dba9..0118c76 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -20,11 +20,11 @@ Quickly, to use::
>>> c.incr('foo') # Increment the 'foo' counter.
>>> c.timing('stats.timed', 320) # Record a 320ms 'stats.timed'.
-You can also add a prefix and/or suffix to all your stats::
+You can also add a prefix to all your stats::
>>> import statsd
- >>> c = statsd.StatsClient('localhost', 8125, prefix='foo', suffix='baz')
- >>> c.incr('bar') # Will be 'foo.bar.baz' in statsd/graphite.
+ >>> c = statsd.StatsClient('localhost', 8125, prefix='foo')
+ >>> c.incr('bar') # Will be 'foo.bar' in statsd/graphite.
Installing
diff --git a/docs/reference.rst b/docs/reference.rst
index f2d4665..72f0fa9 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -21,7 +21,7 @@ statsd_ server supports.
::
- StatsClient(host='localhost', port=8125, prefix=None, suffix=None)
+ StatsClient(host='localhost', port=8125, prefix=None)
Create a new ``StatsClient`` instance with the appropriate connection
and prefix information.
@@ -33,8 +33,6 @@ and prefix information.
* ``prefix``: a prefix to distinguish and group stats from an
application or environment.
-* ``suffix``: a suffix to distinguish and group stats from an
- application or environment.
.. _incr:
diff --git a/statsd/__init__.py b/statsd/__init__.py
index 1fddf0d..1b690f7 100644
--- a/statsd/__init__.py
+++ b/statsd/__init__.py
@@ -28,8 +28,7 @@ if settings:
host = getattr(settings, 'STATSD_HOST', 'localhost')
port = getattr(settings, 'STATSD_PORT', 8125)
prefix = getattr(settings, 'STATSD_PREFIX', None)
- suffix = getattr(settings, 'STATSD_SUFFIX', None)
- statsd = StatsClient(host, port, prefix, suffix)
+ statsd = StatsClient(host, port, prefix)
except (socket.error, socket.gaierror, ImportError):
pass
elif 'STATSD_HOST' in os.environ:
@@ -37,7 +36,6 @@ elif 'STATSD_HOST' in os.environ:
host = os.environ['STATSD_HOST']
port = int(os.environ['STATSD_PORT'])
prefix = os.environ.get('STATSD_PREFIX')
- suffix = os.environ.get('STATSD_SUFFIX')
- statsd = StatsClient(host, port, prefix, suffix)
+ statsd = StatsClient(host, port, prefix)
except (socket.error, socket.gaierror, KeyError):
pass
diff --git a/statsd/client.py b/statsd/client.py
index 0346812..c69405d 100644
--- a/statsd/client.py
+++ b/statsd/client.py
@@ -37,12 +37,11 @@ class Timer(object):
class StatsClient(object):
"""A client for statsd."""
- def __init__(self, host='localhost', port=8125, prefix=None, suffix=None):
+ def __init__(self, host='localhost', port=8125, prefix=None):
"""Create a new client."""
self._addr = (socket.gethostbyname(host), port)
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._prefix = prefix
- self._suffix = suffix
def _after(self, data):
self._send(data)
@@ -95,9 +94,6 @@ class StatsClient(object):
if self._prefix:
stat = '%s.%s' % (self._prefix, stat)
- if self._suffix:
- stat = '%s.%s' % (stat, self._suffix)
-
data = '%s:%s' % (stat, value)
return data
@@ -114,7 +110,6 @@ class Pipeline(StatsClient):
def __init__(self, client):
self._client = client
self._prefix = client._prefix
- self._suffix = client._suffix
self._stats = []
def _after(self, data):
diff --git a/statsd/tests.py b/statsd/tests.py
index bd35f50..1e6f6e0 100644
--- a/statsd/tests.py
+++ b/statsd/tests.py
@@ -12,8 +12,8 @@ from statsd import StatsClient
ADDR = (socket.gethostbyname('localhost'), 8125)
-def _client(prefix=None, suffix=None):
- sc = StatsClient(host=ADDR[0], port=ADDR[1], prefix=prefix, suffix=suffix)
+def _client(prefix=None):
+ sc = StatsClient(host=ADDR[0], port=ADDR[1], prefix=prefix)
sc._sock = mock.Mock()
return sc
@@ -200,20 +200,6 @@ def test_prefix():
_sock_check(sc, 1, 'foo.bar:1|c')
-def test_suffix():
- sc = _client(suffix='foo')
-
- sc.incr('bar')
- _sock_check(sc, 1, 'bar.foo:1|c')
-
-
-def test_prefix_and_suffix():
- sc = _client(prefix='fooprefix', suffix='foosuffix')
-
- sc.incr('bar')
- _sock_check(sc, 1, 'fooprefix.bar.foosuffix:1|c')
-
-
def _timer_check(cl, count, start, end):
eq_(cl._sock.sendto.call_count, count)
value = cl._sock.sendto.call_args[0][0].decode('ascii')