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)
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')