def _setup(self): from kaneda import Metrics from kaneda.utils import import_class, get_object_from_settings from kaneda.exceptions import UnexistingKanedaClass, SettingsError from . import settings if settings.DEBUG: backend_class = import_class('kaneda.backends.LoggerBackend') if settings.LOGGER: backend = backend_class(logger=logging.getLogger(settings.LOGGER)) elif settings.LOGGER_FILENAME: backend = backend_class(filename=settings.LOGGER_FILENAME) else: backend = backend_class() _metrics = Metrics(backend=backend) else: if not settings.BACKEND and not settings.QUEUE: raise SettingsError('You need to set KANEDA_BACKEND or KANEDA_QUEUE on settings.py to django_kaneda') if settings.BACKEND: try: backend = get_object_from_settings(settings.BACKEND, settings) _metrics = Metrics(backend=backend) except UnexistingKanedaClass: raise UnexistingKanedaClass('The selected KANEDA_BACKEND class does not exists.') if settings.QUEUE: try: queue = get_object_from_settings(settings.QUEUE, settings) _metrics = Metrics(queue=queue) except UnexistingKanedaClass: raise UnexistingKanedaClass('The selected KANEDA_QUEUE class does not exists.') self._wrapped = _metrics
def test_logger_metric(self, logger_backend, logger_filename): metrics = Metrics(backend=logger_backend) metrics.gauge('test_gauge', 42) with open(logger_filename) as f: lines = f.readlines() assert lines result = lines[-1].split(' - ')[2] assert result assert 'test_gauge' in result
def test_influx_metric(self, influx_backend): metrics = Metrics(backend=influx_backend) result = metrics.gauge('test_gauge', 42) assert result
def test_rethink_metric(self, rethink_backend): metrics = Metrics(backend=rethink_backend) result = metrics.gauge('test_gauge', 42) assert result assert result['inserted'] == 1
def test_mongo_metric(self, mongo_backend): metrics = Metrics(backend=mongo_backend) result = metrics.gauge('test_gauge', 42) assert result assert result.inserted_id
def test_celery(self, celery_queue): metrics = Metrics(queue=celery_queue) result = metrics.gauge('test_gauge_celery', 1) assert result
def test_rq(self, rq_queue): metrics = Metrics(queue=rq_queue) result = metrics.gauge('test_gauge_rq', 1) assert result
def test_benchmark_elasticsearch(self, elasticsearch_backend, benchmark): metrics = Metrics(backend=elasticsearch_backend) benchmark(metrics.gauge, 'benchmark_elasticsearch', 1)
def test_benchmark_rethink(self, rethink_backend, benchmark): metrics = Metrics(backend=rethink_backend) benchmark(metrics.gauge, 'benchmark_mongo', 1)
def test_benchmark_mongo(self, mongo_backend, benchmark): metrics = Metrics(backend=mongo_backend) benchmark(metrics.gauge, 'benchmark_mongo', 1)
def test_elasticsearch_metric(self, elasticsearch_backend): metrics = Metrics(backend=elasticsearch_backend) result = metrics.gauge('test_gauge', 42) assert result assert result['_id']
def test_benchmark_rq(self, rq_queue, benchmark): metrics = Metrics(queue=rq_queue) benchmark(metrics.gauge, 'benchmark_rq', 1)
def test_zmq(self, zmq_queue): metrics = Metrics(queue=zmq_queue) metrics.gauge('test_gauge_rq', 1) zmq_queue.socket.close()
def test_benchmark_zmq(self, zmq_queue, benchmark): metrics = Metrics(queue=zmq_queue) benchmark(metrics.gauge, 'benchmark_zmq', 1)
def test_benchmark_celery(self, celery_queue, benchmark): metrics = Metrics(queue=celery_queue) benchmark(metrics.gauge, 'benchmark_celery', 1)
def metrics(self, dummy_backend): return Metrics(backend=dummy_backend)