0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-06-29 07:58:19 +02:00

Have all @metrics.counted use a single metric name vectored on the method name, rather than a brand new scalar counter per counted method

This commit is contained in:
Paul "LeoNerd" Evans 2015-03-06 15:39:14 +00:00
parent b3a0179d64
commit 0b96bb793e

View file

@ -63,10 +63,17 @@ class Metrics(object):
def counted(self, func):
""" A method decorator that registers a counter, to count invocations
of this method. """
counter = self.register_counter(func.__name__)
if not hasattr(self, "method_counter"):
self.method_counter = self.register_counter(
"calls",
labels=["method"]
)
counter = self.method_counter
name = func.__name__
def wrapped(*args, **kwargs):
counter.inc()
counter.inc(name)
return func(*args, **kwargs)
return wrapped