##// END OF EJS Templates
deps: bumped urllib3==1.26.20
deps: bumped urllib3==1.26.20

File last commit:

r1250:2c57bb5b default
r1335:cd3f3da3 default
Show More
__init__.py
51 lines | 1.5 KiB | text/x-python | PythonLexer
application: added statsd client for sending usage statistics.
r920 import logging
from .stream import TCPStatsClient, UnixSocketStatsClient # noqa
from .udp import StatsClient # noqa
HOST = 'localhost'
PORT = 8125
IPV6 = False
PREFIX = None
MAXUDPSIZE = 512
log = logging.getLogger('rhodecode.statsd')
def statsd_config(config, prefix='statsd.'):
_config = {}
core: synced vendor/ext_json with ce for better compatability
r1250 for key in list(config.keys()):
application: added statsd client for sending usage statistics.
r920 if key.startswith(prefix):
_config[key[len(prefix):]] = config[key]
return _config
def client_from_config(configuration, prefix='statsd.', **kwargs):
from pyramid.settings import asbool
_config = statsd_config(configuration, prefix)
core: synced vendor/ext_json with ce for better compatability
r1250 statsd_flag = _config.get('enabled')
application: added statsd client for sending usage statistics.
r920 statsd_enabled = asbool(_config.pop('enabled', False))
if not statsd_enabled:
core: synced vendor/ext_json with ce for better compatability
r1250 log.debug('statsd client not enabled by statsd.enabled = %s flag, skipping...', statsd_flag)
application: added statsd client for sending usage statistics.
r920 return
host = _config.pop('statsd_host', HOST)
port = _config.pop('statsd_port', PORT)
prefix = _config.pop('statsd_prefix', PREFIX)
maxudpsize = _config.pop('statsd_maxudpsize', MAXUDPSIZE)
ipv6 = asbool(_config.pop('statsd_ipv6', IPV6))
log.debug('configured statsd client %s:%s', host, port)
statsd: use safe mode and disable statsd if we can't connect
r1030 try:
client = StatsClient(
host=host, port=port, prefix=prefix, maxudpsize=maxudpsize, ipv6=ipv6)
except Exception:
log.exception('StatsD is enabled, but failed to connect to statsd server, fallback: disable statsd')
client = None
return client
application: added statsd client for sending usage statistics.
r920
def get_statsd_client(request):
return client_from_config(request.registry.settings)