Пример #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)
Пример #2
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')
Пример #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')
Пример #4
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)
Пример #5
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)
Пример #6
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)