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