From eb3bf34066f5edcb22e6fa6ed5712b2af0eb9e53 Mon Sep 17 00:00:00 2001 From: Scott Sanders Date: Fri, 12 Sep 2014 13:52:45 -0400 Subject: [PATCH] Prefix statsd metric strings with the prefix --- gunicorn/instrument/statsd.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gunicorn/instrument/statsd.py b/gunicorn/instrument/statsd.py index 8c177cab..6ee30400 100644 --- a/gunicorn/instrument/statsd.py +++ b/gunicorn/instrument/statsd.py @@ -27,6 +27,7 @@ class Statsd(Logger): Logger.__init__(self, cfg) try: host, port = cfg.statsd_host + self.prefix = cfg.statsd_prefix self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock.connect((host, int(port))) except Exception: @@ -98,27 +99,27 @@ class Statsd(Logger): def gauge(self, name, value): try: if self.sock: - self.sock.send("{0}:{1}|g".format(name, value)) + self.sock.send("{0}{1}:{2}|g".format(self.prefix, name, value)) except Exception: pass def increment(self, name, value, sampling_rate=1.0): try: if self.sock: - self.sock.send("{0}:{1}|c|@{2}".format(name, value, sampling_rate)) + self.sock.send("{0}{1}:{2}|c|@{3}".format(self.prefix, name, value, sampling_rate)) except Exception: pass def decrement(self, name, value, sampling_rate=1.0): try: if self.sock: - self.sock.send("{0}:-{1}|c|@{2}".format(name, value, sampling_rate)) + self.sock.send("{0){1}:-{2}|c|@{3}".format(self.prefix, name, value, sampling_rate)) except Exception: pass def histogram(self, name, value): try: if self.sock: - self.sock.send("{0}:{1}|ms".format(name, value)) + self.sock.send("{0}{1}:{2}|ms".format(self.prefix, name, value)) except Exception: pass