Пример #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)
Пример #2
0
def prometheus_metrics():

    total_alert_gauge.set(Alert.get_count())

    output = Gauge.find_all()
    output += Counter.find_all()
    output += Timer.find_all()

    return Response([o.serialize(format='prometheus') for o in output],
                    content_type='text/plain; version=0.0.4; charset=utf-8')
Пример #3
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)
Пример #4
0
def prometheus_metrics():

    total_alert_gauge.set(Alert.get_count())

    output = Gauge.find_all()
    output += Counter.find_all()
    output += Timer.find_all()

    return Response(
        [o.serialize(format='prometheus') for o in output],
        content_type='text/plain; version=0.0.4; charset=utf-8'
    )
Пример #5
0
def status():

    now = int(time.time() * 1000)
    total_alert_gauge.set(Alert.get_count())

    metrics = Gauge.find_all()
    metrics.extend(Counter.find_all())
    metrics.extend(Timer.find_all())
    metrics.extend(Switch.find_all())

    return jsonify(application="alerta", version=__version__, time=now, uptime=int(now - started),
                   metrics=[metric.serialize() for metric in metrics])
Пример #6
0
def status():

    now = int(time.time() * 1000)
    total_alert_gauge.set(Alert.get_count())

    metrics = Gauge.find_all()
    metrics.extend(Counter.find_all())
    metrics.extend(Timer.find_all())
    metrics.extend(Switch.find_all())

    return jsonify(application="alerta", version=__version__, time=now, uptime=int(now - started),
                   metrics=[metric.serialize() for metric in metrics])
Пример #7
0
from alerta.exceptions import ApiError
from alerta.models.alert import Alert
from alerta.models.heartbeat import Heartbeat
from alerta.models.metrics import Gauge, Counter, Timer
from alerta.models.switch import Switch, SwitchState
from alerta.version import __version__

from . import mgmt

switches = [
    Switch('auto-refresh-allow', 'Alerta console auto-refresh',
           'Allow consoles to auto-refresh alerts', SwitchState.ON),
    Switch('sender-api-allow', 'API alert submission',
           'Allow alerts to be submitted via the API', SwitchState.ON)
]
total_alert_gauge = Gauge('alerts', 'total', 'Total alerts',
                          'Total number of alerts in the database')

started = time.time() * 1000


@mgmt.route('/management', methods=['OPTIONS', 'GET'])
@cross_origin()
def management():

    endpoints = [
        url_for('mgmt.manifest'),
        url_for('mgmt.properties'),
        url_for('mgmt.switchboard'),
        url_for('mgmt.good_to_go'),
        url_for('mgmt.health_check'),
        url_for('mgmt.housekeeping'),