Exemple #1
0
def status():

    total_alert_gauge.set(db.get_count())

    metrics = Gauge.get_gauges(format='json')
    metrics.extend(Counter.get_counters(format='json'))
    metrics.extend(Timer.get_timers(format='json'))

    auto_refresh_allow = {
        "group": "switch",
        "name": "auto_refresh_allow",
        "type": "text",
        "title": "Alert console auto-refresh",
        "description":
        "Allows auto-refresh of alert consoles to be turned off remotely",
        "value": "ON" if Switch.get('auto-refresh-allow').is_on() else "OFF",
    }
    metrics.append(auto_refresh_allow)

    now = int(time.time() * 1000)

    return jsonify(application="alerta",
                   version=__version__,
                   time=now,
                   uptime=int(now - started),
                   metrics=metrics)
Exemple #2
0
    def test_metrics(self):

        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.get_gauges() 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.get_timers() if t.title == 'Test timer'][0]
        self.assertGreaterEqual(timer.count, 1)
        self.assertGreaterEqual(timer.total_time, 999)
Exemple #3
0
def prometheus_metrics():

    total_alert_gauge.set(db.get_count())

    output = Gauge.get_gauges(format='prometheus')
    output += Counter.get_counters(format='prometheus')
    output += Timer.get_timers(format='prometheus')

    return Response(output, content_type='text/plain; version=0.0.4; charset=utf-8')
Exemple #4
0
def prometheus_metrics():

    total_alert_gauge.set(db.get_count())

    output = Gauge.get_gauges(format='prometheus')
    output += Counter.get_counters(format='prometheus')
    output += Timer.get_timers(format='prometheus')

    return Response(output,
                    content_type='text/plain; version=0.0.4; charset=utf-8')
Exemple #5
0
    def test_metrics(self):

        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.get_gauges() 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.get_timers() if t.title == 'Test timer'][0]
        self.assertGreaterEqual(timer.count, 1)
        self.assertGreaterEqual(timer.total_time, 999)
Exemple #6
0
def status():

    total_alert_gauge.set(db.get_count())

    metrics = Gauge.get_gauges()
    metrics.extend(Counter.get_counters())
    metrics.extend(Timer.get_timers())

    auto_refresh_allow = {
        "group": "switch",
        "name": "auto_refresh_allow",
        "type": "text",
        "title": "Alert console auto-refresh",
        "description": "Allows auto-refresh of alert consoles to be turned off remotely",
        "value": "ON" if Switch.get("auto-refresh-allow").is_on() else "OFF",
    }
    metrics.append(auto_refresh_allow)

    now = int(time.time() * 1000)

    return jsonify(application="alerta", version=__version__, time=now, uptime=int(now - started), metrics=metrics)
Exemple #7
0
from alerta.app import app, db
from alerta.app.auth import permission
from alerta.app.switch import Switch, SwitchState
from alerta.app.metrics import Gauge, Counter, Timer
from alerta import build
from alerta.version import __version__

LOG = app.logger

switches = [
    Switch('auto-refresh-allow', 'Allow consoles to auto-refresh alerts',
           SwitchState.to_state(app.config['AUTO_REFRESH_ALLOW'])),
    Switch('sender-api-allow', 'Allow alerts to be submitted via the API',
           SwitchState.to_state(app.config['SENDER_API_ALLOW']))
]
total_alert_gauge = Gauge('alerts', 'total', 'Total alerts',
                          'Total number of alerts in the database')
started = time.time() * 1000


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

    endpoints = [
        url_for('manifest'),
        url_for('properties'),
        url_for('switchboard'),
        url_for('good_to_go'),
        url_for('health_check'),
        url_for('status'),
        url_for('prometheus_metrics')