Format floating point gauge values; fix tests.
This commit is contained in:
parent
7c64944a7b
commit
c2d934ea6b
|
@ -9,6 +9,10 @@ import time
|
|||
E_NOSTART = 'you must call start() before stop(). ignoring.'
|
||||
|
||||
|
||||
def _format_float(val):
|
||||
return ('%f' % val).rstrip('0').rstrip('.')
|
||||
|
||||
|
||||
class StatsClient(object):
|
||||
|
||||
"Simple client to exercise the statsd server."
|
||||
|
@ -25,7 +29,7 @@ class StatsClient(object):
|
|||
self._send('%s:%d|ms' % (key, round(timestamp)), sample_rate)
|
||||
|
||||
def gauge(self, key, value, sample_rate=1):
|
||||
self._send('%s:%d|g' % (key, value), sample_rate)
|
||||
self._send('%s:%s|g' % (key, _format_float(value)), sample_rate)
|
||||
|
||||
def increment(self, key, sample_rate=1):
|
||||
return self.counter(key, 1, sample_rate)
|
||||
|
|
|
@ -56,9 +56,9 @@ class StatsClientTest(unittest.TestCase):
|
|||
def test_gauge(self):
|
||||
self._cli.gauge('foo', 5)
|
||||
self.assertEquals(self._cli.packets[-1], ('foo:5|g', 1))
|
||||
self._cli.counter('foo', -50)
|
||||
self._cli.gauge('foo', -50)
|
||||
self.assertEquals(self._cli.packets[-1], ('foo:-50|g', 1))
|
||||
self._cli.counter('foo', 5.9)
|
||||
self._cli.gauge('foo', 5.9)
|
||||
self.assertEquals(self._cli.packets[-1], ('foo:5.9|g', 1))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue