From ccd36188bc86ed2f6747bc39305fdf50cee8ccb8 Mon Sep 17 00:00:00 2001 From: Adam Hitchcock Date: Tue, 3 Apr 2012 16:51:13 -0700 Subject: [PATCH] Added gauge to client --- pystatsd/statsd.py | 9 ++++++++- statsd_test.py | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pystatsd/statsd.py b/pystatsd/statsd.py index 70aea0f..2f3fe3e 100644 --- a/pystatsd/statsd.py +++ b/pystatsd/statsd.py @@ -35,7 +35,6 @@ def timing_since(self, stat, start, sample_rate=1): """ self.timing(stat, int((time.time() - start) * 1000000), sample_rate) - def timing(self, stat, time, sample_rate=1): """ Log timing information for a single stat @@ -44,6 +43,14 @@ def timing(self, stat, time, sample_rate=1): stats = {stat: "%f|ms" % time} self.send(stats, sample_rate) + def gauge(self, stat, value, sample_rate=1): + """ + Log gauge information for a single stat + >>> statsd_client.gauge('some.gauge',42) + """ + stats = {stat: "%f|g" % value} + self.send(stats, sample_rate) + def increment(self, stats, sample_rate=1): """ Increments one or more stats counters diff --git a/statsd_test.py b/statsd_test.py index 393acde..12bb37c 100644 --- a/statsd_test.py +++ b/statsd_test.py @@ -2,11 +2,12 @@ from pystatsd import Client, Server -sc = Client('localhost',8125) +sc = Client('localhost', 8125) -sc.timing('python_test.time',500) +sc.timing('python_test.time', 500) sc.increment('python_test.inc_int') sc.decrement('python_test.decr_int') +sc.gauge('python_test.gauge', 42) srvr = Server(debug=True) srvr.serve()