##// END OF EJS Templates
makefiles: synced makefiles
makefiles: synced makefiles

File last commit:

r5323:905c58f2 default
r5419:887a9753 default
Show More
statsd_client.py
52 lines | 1.2 KiB | text/x-python | PythonLexer
metrics: added new statsd client and enabled new metrics on app
r4792 from rhodecode.lib._vendor.statsd import client_from_config
class StatsdClientNotInitialised(Exception):
pass
class _Singleton(type):
"""A metaclass that creates a Singleton base class when called."""
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
modernize: python3 updates
r5096 cls._instances[cls] = super().__call__(*args, **kwargs)
metrics: added new statsd client and enabled new metrics on app
r4792 return cls._instances[cls]
class Singleton(_Singleton("SingletonMeta", (object,), {})):
pass
class StatsdClientClass(Singleton):
setup_run = False
statsd_client = None
statsd = None
statsd: added special repr for statsdclient for nicer debug
r5323 def __repr__(self):
return f"{self.__class__}(statsd={self.statsd})"
metrics: added new statsd client and enabled new metrics on app
r4792 def __getattribute__(self, name):
if name.startswith("statsd"):
if self.setup_run:
modernize: python3 updates
r5096 return super().__getattribute__(name)
metrics: added new statsd client and enabled new metrics on app
r4792 else:
return None
#raise StatsdClientNotInitialised("requested key was %s" % name)
modernize: python3 updates
r5096 return super().__getattribute__(name)
metrics: added new statsd client and enabled new metrics on app
r4792
def setup(self, settings):
"""
Initialize the client
"""
statsd = client_from_config(settings)
self.statsd = statsd
self.statsd_client = statsd
self.setup_run = True
StatsdClient = StatsdClientClass()