summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Hensley <spaceboy@indirect.com>2013-12-03 20:49:42 (GMT)
committerPatrick Hensley <spaceboy@indirect.com>2013-12-03 20:52:51 (GMT)
commitc2d934ea6bc3b48bbe2a673a3ea7e416ced759df (patch)
tree811f2a407df51f4ff73b809ca68eae60b757ed98
parent7c64944a7bced9a7c942f60bf12123349cbedaf4 (diff)
downloadgstatsd-c2d934ea6bc3b48bbe2a673a3ea7e416ced759df.zip
gstatsd-c2d934ea6bc3b48bbe2a673a3ea7e416ced759df.tar.gz
gstatsd-c2d934ea6bc3b48bbe2a673a3ea7e416ced759df.tar.bz2
Format floating point gauge values; fix tests.
-rw-r--r--gstatsd/client.py6
-rw-r--r--gstatsd/client_test.py4
2 files changed, 7 insertions, 3 deletions
diff --git a/gstatsd/client.py b/gstatsd/client.py
index 34bcf8a..f6194b8 100644
--- a/gstatsd/client.py
+++ b/gstatsd/client.py
@@ -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)
diff --git a/gstatsd/client_test.py b/gstatsd/client_test.py
index 0783098..1f5e8f4 100644
--- a/gstatsd/client_test.py
+++ b/gstatsd/client_test.py
@@ -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))