From 97777fa660c1cee5c2c88b1ea903913827b7ce0e Mon Sep 17 00:00:00 2001 From: ronan-ln Date: Mon, 6 Oct 2014 00:13:08 +0100 Subject: [PATCH 1/2] server.py now allows empty string prefix In the previosu implementation, when passing the empty string to the prefix parameter, the final key constructed was .key when it should have been key. --- pystatsd/server.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pystatsd/server.py b/pystatsd/server.py index 40118c8..e262e00 100644 --- a/pystatsd/server.py +++ b/pystatsd/server.py @@ -35,11 +35,11 @@ def _clean_key(k): -TIMER_MSG = '''%(prefix)s.%(key)s.lower %(min)s %(ts)s -%(prefix)s.%(key)s.count %(count)s %(ts)s -%(prefix)s.%(key)s.mean %(mean)s %(ts)s -%(prefix)s.%(key)s.upper %(max)s %(ts)s -%(prefix)s.%(key)s.upper_%(pct_threshold)s %(max_threshold)s %(ts)s +TIMER_MSG = '''%(prefix)s%(key)s.lower %(min)s %(ts)s +%(prefix)s%(key)s.count %(count)s %(ts)s +%(prefix)s%(key)s.mean %(mean)s %(ts)s +%(prefix)s%(key)s.upper %(max)s %(ts)s +%(prefix)s%(key)s.upper_%(pct_threshold)s %(max_threshold)s %(ts)s ''' @@ -74,13 +74,13 @@ def __init__(self, pct_threshold=90, debug=False, transport='graphite', self.graphite_host = graphite_host self.graphite_port = graphite_port self.no_aggregate_counters = no_aggregate_counters - self.counters_prefix = counters_prefix - self.timers_prefix = timers_prefix + self.counters_prefix = counters_prefix + '.' if counters_prefix else '' + self.timers_prefix = timers_prefix + '.' if timers_prefix else '' self.debug = debug self.expire = expire # For services like Hosted Graphite, etc. - self.global_prefix = global_prefix + self.global_prefix = global_prefix + '.' if timers_prefix else '' self.counters = {} self.timers = {} @@ -169,7 +169,7 @@ def flush(self): print("Sending %s => count=%s" % (k, v)) if self.transport == 'graphite': - msg = '%s.%s %s %s\n' % (self.counters_prefix, k, v, ts) + msg = '%s%s %s %s\n' % (self.counters_prefix, k, v, ts) stat_string += msg elif self.transport == 'ganglia': # We put counters in _counters group. Underscore is to make sure counters show up @@ -195,7 +195,7 @@ def flush(self): if self.transport == 'graphite': # note: counters and gauges implicitly end up in the same namespace - msg = '%s.%s %s %s\n' % (self.counters_prefix, k, v, ts) + msg = '%s%s %s %s\n' % (self.counters_prefix, k, v, ts) stat_string += msg elif self.transport == 'ganglia': g.send(k, v, "double", "count", "both", 60, self.dmax, "_gauges", self.ganglia_spoof_host) @@ -275,7 +275,7 @@ def flush(self): # Prepend stats with Hosted Graphite API key if necessary if self.global_prefix: stat_string = '\n'.join([ - '%s.%s' % (self.global_prefix, s) for s in stat_string.split('\n')[:-1] + '%s%s' % (self.global_prefix, s) for s in stat_string.split('\n')[:-1] ]) graphite = socket.socket() From aa32c57d0c5489b7c26d4e8f1d62214b12cdaaee Mon Sep 17 00:00:00 2001 From: ronan-ln Date: Mon, 6 Oct 2014 11:12:58 +0100 Subject: [PATCH 2/2] server.py - Fixed the global_prefix initialisation --- pystatsd/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pystatsd/server.py b/pystatsd/server.py index e262e00..1888b0f 100644 --- a/pystatsd/server.py +++ b/pystatsd/server.py @@ -80,7 +80,7 @@ def __init__(self, pct_threshold=90, debug=False, transport='graphite', self.expire = expire # For services like Hosted Graphite, etc. - self.global_prefix = global_prefix + '.' if timers_prefix else '' + self.global_prefix = global_prefix + '.' if global_prefix else '' self.counters = {} self.timers = {}