##// END OF EJS Templates
feat(statsd): added extra logging into statsd initalization
super-admin -
r5320:2dcf7cd2 default
parent child Browse files
Show More
@@ -1,52 +1,53 b''
1 1
2 2
3 3 import logging
4 4
5 5 from .stream import TCPStatsClient, UnixSocketStatsClient # noqa
6 6 from .udp import StatsClient # noqa
7 7
8 8 HOST = 'localhost'
9 9 PORT = 8125
10 10 IPV6 = False
11 11 PREFIX = None
12 12 MAXUDPSIZE = 512
13 13
14 14 log = logging.getLogger('rhodecode.statsd')
15 15
16 16
17 17 def statsd_config(config, prefix='statsd.'):
18 18 _config = {}
19 19 for key in list(config.keys()):
20 20 if key.startswith(prefix):
21 21 _config[key[len(prefix):]] = config[key]
22 22 return _config
23 23
24 24
25 25 def client_from_config(configuration, prefix='statsd.', **kwargs):
26 26 from pyramid.settings import asbool
27 27
28 28 _config = statsd_config(configuration, prefix)
29 statsd_flag = _config.get('enabled')
29 30 statsd_enabled = asbool(_config.pop('enabled', False))
30 31 if not statsd_enabled:
31 log.debug('statsd client not enabled by statsd.enabled = flag, skipping...')
32 log.debug('statsd client not enabled by statsd.enabled = %s flag, skipping...', statsd_flag)
32 33 return
33 34
34 35 host = _config.pop('statsd_host', HOST)
35 36 port = _config.pop('statsd_port', PORT)
36 37 prefix = _config.pop('statsd_prefix', PREFIX)
37 38 maxudpsize = _config.pop('statsd_maxudpsize', MAXUDPSIZE)
38 39 ipv6 = asbool(_config.pop('statsd_ipv6', IPV6))
39 40 log.debug('configured statsd client %s:%s', host, port)
40 41
41 42 try:
42 43 client = StatsClient(
43 44 host=host, port=port, prefix=prefix, maxudpsize=maxudpsize, ipv6=ipv6)
44 45 except Exception:
45 46 log.exception('StatsD is enabled, but failed to connect to statsd server, fallback: disable statsd')
46 47 client = None
47 48
48 49 return client
49 50
50 51
51 52 def get_statsd_client(request):
52 53 return client_from_config(request.registry.settings)
General Comments 0
You need to be logged in to leave comments. Login now