mirror of
https://github.com/ansible/awx.git
synced 2026-07-10 15:58:05 -02:30
Integrate statsd metrics into ansible playbook execution.
* Add dependencies for pystatsd and django-statsd-mozilla * Default turned off except for development environment * Modify docker-compose to install statsd/graphite host
This commit is contained in:
45
awx/lib/metrics.py
Normal file
45
awx/lib/metrics.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from functools import wraps
|
||||
|
||||
from django_statsd.clients import statsd
|
||||
|
||||
|
||||
def task_timer(fn):
|
||||
@wraps(fn)
|
||||
def __wrapped__(self, *args, **kwargs):
|
||||
statsd.incr('tasks.{}.{}.count'.format(
|
||||
self.name.rsplit('.', 1)[-1],
|
||||
fn.__name__
|
||||
))
|
||||
with statsd.timer('tasks.{}.{}.timer'.format(
|
||||
self.name.rsplit('.', 1)[-1],
|
||||
fn.__name__
|
||||
)):
|
||||
return fn(self, *args, **kwargs)
|
||||
return __wrapped__
|
||||
|
||||
class BaseTimer(object):
|
||||
def __init__(self, name, prefix=None):
|
||||
self.name = name.rsplit('.', 1)[-1]
|
||||
if prefix:
|
||||
self.name = '{}.{}'.format(prefix, self.name)
|
||||
|
||||
def __call__(self, fn):
|
||||
@wraps(fn)
|
||||
def __wrapped__(obj, *args, **kwargs):
|
||||
statsd.incr('{}.{}.count'.format(
|
||||
self.name,
|
||||
fn.__name__
|
||||
))
|
||||
with statsd.timer('{}.{}.timer'.format(
|
||||
self.name,
|
||||
fn.__name__
|
||||
)):
|
||||
return fn(obj, *args, **kwargs)
|
||||
return __wrapped__
|
||||
Reference in New Issue
Block a user