summaryrefslogtreecommitdiff
path: root/statsd
diff options
context:
space:
mode:
authortrbs <trbs@trbs.net>2013-09-17 00:57:41 +0200
committertrbs <trbs@trbs.net>2013-09-17 00:57:41 +0200
commitaad3c697e0b11a6343ff18f69084e56925b2b355 (patch)
tree3a1625a023afce42a08001ca58724bc681e0c54c /statsd
parentda0005cb30fac365c7bc3a9ab9a4824e1a9c3a49 (diff)
downloadpystatsd-aad3c697e0b11a6343ff18f69084e56925b2b355.tar.gz
add maxudpsize option
allows to control the maximum udp packet size. when pipelining a lot of metrics within a controlled network or to 127.0.0.1 it can be desirable to lower the number of udp packets by sending larger onces. the documentation reflects that this option is not for the faint hearted, should not be used on the internet and should be handled with extreme care.
Diffstat (limited to 'statsd')
-rw-r--r--statsd/__init__.py6
-rw-r--r--statsd/client.py6
2 files changed, 8 insertions, 4 deletions
diff --git a/statsd/__init__.py b/statsd/__init__.py
index 1b690f7..e47a620 100644
--- a/statsd/__init__.py
+++ b/statsd/__init__.py
@@ -28,7 +28,8 @@ if settings:
host = getattr(settings, 'STATSD_HOST', 'localhost')
port = getattr(settings, 'STATSD_PORT', 8125)
prefix = getattr(settings, 'STATSD_PREFIX', None)
- statsd = StatsClient(host, port, prefix)
+ maxudpsize = getattr(settings, 'STATSD_MAXUDPSIZE', 512)
+ statsd = StatsClient(host, port, prefix, maxudpsize)
except (socket.error, socket.gaierror, ImportError):
pass
elif 'STATSD_HOST' in os.environ:
@@ -36,6 +37,7 @@ elif 'STATSD_HOST' in os.environ:
host = os.environ['STATSD_HOST']
port = int(os.environ['STATSD_PORT'])
prefix = os.environ.get('STATSD_PREFIX')
- statsd = StatsClient(host, port, prefix)
+ maxudpsize = int(os.environ.get('STATSD_MAXUDPSIZE', 512))
+ statsd = StatsClient(host, port, prefix, maxudpsize)
except (socket.error, socket.gaierror, KeyError):
pass
diff --git a/statsd/client.py b/statsd/client.py
index fd5e43f..5a64e6d 100644
--- a/statsd/client.py
+++ b/statsd/client.py
@@ -37,11 +37,12 @@ class Timer(object):
class StatsClient(object):
"""A client for statsd."""
- def __init__(self, host='localhost', port=8125, prefix=None):
+ def __init__(self, host='localhost', port=8125, prefix=None, maxudpsize=512):
"""Create a new client."""
self._addr = (socket.gethostbyname(host), port)
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._prefix = prefix
+ self._maxudpsize = maxudpsize
def _after(self, data):
self._send(data)
@@ -108,6 +109,7 @@ class Pipeline(StatsClient):
def __init__(self, client):
self._client = client
self._prefix = client._prefix
+ self._maxudpsize = client._maxudpsize
self._stats = []
def _after(self, data):
@@ -126,7 +128,7 @@ class Pipeline(StatsClient):
data = self._stats.pop(0)
while self._stats:
stat = self._stats.pop(0)
- if len(stat) + len(data) + 1 >= 512:
+ if len(stat) + len(data) + 1 >= self._maxudpsize:
self._client._after(data)
data = stat
else: