Ejemplo n.º 1
0
    def test_metrics(self):

        with self.app.test_request_context():
            self.app.preprocess_request()

            test_gauge = Gauge(
                group='test',
                name='gauge',
                title='Test gauge',
                description='total time to process timed events')
            test_gauge.set(500)

            gauge = [g for g in Gauge.find_all() if g.title == 'Test gauge'][0]
            self.assertGreaterEqual(gauge.value, 500)

            test_timer = Timer(
                group='test',
                name='timer',
                title='Test timer',
                description='total time to process timed events')
            recv_started = test_timer.start_timer()
            time.sleep(1)
            test_timer.stop_timer(recv_started)

            timer = [t for t in Timer.find_all() if t.title == 'Test timer'][0]
            self.assertGreaterEqual(timer.count, 1)
            self.assertGreaterEqual(timer.total_time, 999)
Ejemplo n.º 2
0
from alerta.auth.decorators import permission
from alerta.exceptions import (ApiError, BlackoutPeriod, HeartbeatReceived,
                               InvalidAction, RateLimit, RejectException)
from alerta.models.alert import Alert
from alerta.models.enums import Scope
from alerta.models.metrics import Timer, timer
from alerta.models.switch import Switch
from alerta.utils.api import (assign_customer, process_action, process_alert,
                              process_status)
from alerta.utils.audit import write_audit_trail
from alerta.utils.paging import Page
from alerta.utils.response import jsonp

from . import api

receive_timer = Timer('alerts', 'received', 'Received alerts',
                      'Total time and number of received alerts')
gets_timer = Timer('alerts', 'queries', 'Alert queries',
                   'Total time and number of alert queries')
status_timer = Timer('alerts', 'status', 'Alert status change',
                     'Total time and number of alerts with status changed')
tag_timer = Timer('alerts', 'tagged', 'Tagging alerts',
                  'Total time to tag number of alerts')
untag_timer = Timer('alerts', 'untagged', 'Removing tags from alerts',
                    'Total time to un-tag and number of alerts')
attrs_timer = Timer('alerts', 'attributes', 'Alert attributes change',
                    'Total time and number of alerts with attributes changed')
delete_timer = Timer('alerts', 'deleted', 'Deleted alerts',
                     'Total time and number of deleted alerts')
count_timer = Timer('alerts', 'counts', 'Count alerts',
                    'Total time and number of count queries')