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

pull/108/head
Paul "LeoNerd" Evans 2015-03-06 15:39:14 +00:00
parent b3a0179d64
commit 0b96bb793e
1 changed files with 9 additions and 2 deletions

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