Simpler statsd integration

No need to specify a logger class.
--statsd-to is enough to trigger the Statsd logger automatically
This commit is contained in:
Alexis Le-Quoc 2014-06-18 21:33:04 -04:00
parent c3421a833d
commit 05051aa8b2
3 changed files with 9 additions and 4 deletions

View File

@ -154,7 +154,7 @@ statsD consumer.
To use this instrumentation mechanism, simply use a new logger:: To use this instrumentation mechanism, simply use a new logger::
$ gunicorn --logging-class gunicorn.instrument.statsd.Statsd ... $ gunicorn --statsd-to localhost:8125 ...
The `Statsd` logger overrides `gunicorn.glogging.Logger` to track The `Statsd` logger overrides `gunicorn.glogging.Logger` to track
all requests. The following metrics are generated: all requests. The following metrics are generated:

View File

@ -142,8 +142,13 @@ class Config(object):
if uri == "simple": if uri == "simple":
# support the default # support the default
uri = "gunicorn.glogging.Logger" uri = "gunicorn.glogging.Logger"
logger_class = util.load_class(uri, # if statsd is on, automagically switch to the statsd logger
if 'statsd_to' in self.settings:
logger_class = util.load_class("gunicorn.instrument.statsd.Statsd",
section="gunicorn.loggers")
else:
logger_class = util.load_class(uri,
default="gunicorn.glogging.Logger", default="gunicorn.glogging.Logger",
section="gunicorn.loggers") section="gunicorn.loggers")
@ -1639,7 +1644,7 @@ if sys.version_info >= (2, 7):
class StatsdTo(Setting): class StatsdTo(Setting):
name = "statsd_to" name = "statsd_to"
section = "Logging" section = "Logging"
cli = ["--log-statsd-to"] cli = ["--statsd-to"]
meta = "STATSD_ADDR" meta = "STATSD_ADDR"
default = "localhost:8125" default = "localhost:8125"
validator = validate_hostport validator = validate_hostport