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})