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:
parent
b3a0179d64
commit
0b96bb793e
|
@ -63,10 +63,17 @@ class Metrics(object):
|
||||||
def counted(self, func):
|
def counted(self, func):
|
||||||
""" A method decorator that registers a counter, to count invocations
|
""" A method decorator that registers a counter, to count invocations
|
||||||
of this method. """
|
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):
|
def wrapped(*args, **kwargs):
|
||||||
counter.inc()
|
counter.inc(name)
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue