django-redis-metrics
django-redis-metrics copied to clipboard
provide a decorator to count how often a function is called
Here's the scenario: My metrics what to track the functions that get called in my code/framework. we could implement this as a decorator
from redis_metrics.decorators import count
@count
def my_func():
....
Then we'd get a key/value in Redis similar to:
my_func: 42
Marking this as an enhancement but it's really more an idea... not sure if if a good one or not.
It would be really cool if metric
could act as a context manager:
with metric('important-code-block'):
# do the important stuff
Implementing this as a ContextDecorator
would also allow us to use it as a decorator
@metric()
def my_func():
...