summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Hensley <spaceboy@indirect.com>2014-02-21 17:08:52 (GMT)
committerPatrick Hensley <spaceboy@indirect.com>2014-02-21 17:08:52 (GMT)
commit3a8683e89d32bcb1b28968e58c0274e5f6805f4f (patch)
treebc8ab1ff4b76a4f8429010532bf6d7cc083d576c
parent8e225b5033c14c522d975945947d641e96442b01 (diff)
parent9418ce78ced8b77b7382792b7866ccdb1fa6ab92 (diff)
downloadgstatsd-3a8683e89d32bcb1b28968e58c0274e5f6805f4f.zip
gstatsd-3a8683e89d32bcb1b28968e58c0274e5f6805f4f.tar.gz
gstatsd-3a8683e89d32bcb1b28968e58c0274e5f6805f4f.tar.bz2
Merge pull request #11 from bbinet/process-data-newline
Process data separated by newlines
-rw-r--r--gstatsd/service.py7
-rw-r--r--gstatsd/service_test.py16
2 files changed, 13 insertions, 10 deletions
diff --git a/gstatsd/service.py b/gstatsd/service.py
index a77beb2..ca9f570 100644
--- a/gstatsd/service.py
+++ b/gstatsd/service.py
@@ -174,7 +174,10 @@ class StatsDaemon(object):
self._sock.bind(self._bindaddr)
while 1:
try:
- self._process(*self._sock.recvfrom(MAX_PACKET))
+ data, _ = self._sock.recvfrom(MAX_PACKET)
+ for p in data.split('\n'):
+ if p:
+ self._process(p)
except Exception, ex:
self.error(str(ex))
@@ -182,7 +185,7 @@ class StatsDaemon(object):
"Shutdown the server"
self.exit("service exiting", code=0)
- def _process(self, data, _):
+ def _process(self, data):
"Process a single packet and update the internal tables."
parts = data.split(':')
if self._debug:
diff --git a/gstatsd/service_test.py b/gstatsd/service_test.py
index 129c96f..7822d7d 100644
--- a/gstatsd/service_test.py
+++ b/gstatsd/service_test.py
@@ -34,37 +34,37 @@ class StatsServiceTest(unittest.TestCase):
def test_counters(self):
pkt = 'foo:1|c'
- self.svc._process(pkt, None)
+ self.svc._process(pkt)
self.assertEquals(self.stats.counts, {'foo': 1})
- self.svc._process(pkt, None)
+ self.svc._process(pkt)
self.assertEquals(self.stats.counts, {'foo': 2})
pkt = 'foo:-1|c'
- self.svc._process(pkt, None)
+ self.svc._process(pkt)
self.assertEquals(self.stats.counts, {'foo': 1})
def test_counters_sampled(self):
pkt = 'foo:1|c|@.5'
- self.svc._process(pkt, None)
+ self.svc._process(pkt)
self.assertEquals(self.stats.counts, {'foo': 2})
def test_timers(self):
pkt = 'foo:20|ms'
- self.svc._process(pkt, None)
+ self.svc._process(pkt)
self.assertEquals(self.stats.timers, {'foo': [20.0]})
pkt = 'foo:10|ms'
- self.svc._process(pkt, None)
+ self.svc._process(pkt)
self.assertEquals(self.stats.timers, {'foo': [20.0, 10.0]})
def test_key_sanitize(self):
pkt = '\t\n#! foo . bar \0 ^:1|c'
- self.svc._process(pkt, None)
+ self.svc._process(pkt)
self.assertEquals(self.stats.counts, {'foo.bar': 1})
def test_key_prefix(self):
args = (':8125', [':2003'], 5, 90, 0, 'pfx')
svc = service.StatsDaemon(*args)
pkt = 'foo:1|c'
- svc._process(pkt, None)
+ svc._process(pkt)
self.assertEquals(svc._stats.counts, {'pfx.foo': 1})