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)
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')
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) return jsonify(application="alerta", time=int(time.time() * 1000), metrics=metrics)
def get_count(query: Query = None) -> Dict[str, Any]: return db.get_count(query)
def get_count(query=None): return db.get_count(query)
gets_started = gets_timer.start_timer() try: query, sort, _, limit, query_time = parse_fields(request) except Exception, e: gets_timer.stop_timer(gets_started) return jsonify(status="error", message=str(e)), 400 fields = dict() fields['history'] = {'$slice': app.config['HISTORY_LIMIT']} try: alerts = db.get_alerts(query=query, fields=fields, sort=sort, limit=limit) except Exception as e: return jsonify(status="error", message=str(e)), 500 total = db.get_count(query=query) # because total may be greater than limit found = 0 severity_count = defaultdict(int) status_count = defaultdict(int) alert_response = list() if len(alerts) > 0: last_time = None for alert in alerts: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url.replace('alerts', 'alert'), alert.id) found += 1 severity_count[body['severity']] += 1
def get_count(query: Query=None) -> Dict[str, Any]: return db.get_count(query)
except Exception, e: gets_timer.stop_timer(gets_started) return jsonify(status="error", message=str(e)), 400 fields = dict() fields['history'] = {'$slice': app.config['HISTORY_LIMIT']} try: alerts = db.get_alerts(query=query, fields=fields, sort=sort, limit=limit) except Exception as e: return jsonify(status="error", message=str(e)), 500 total = db.get_count( query=query) # because total may be greater than limit found = 0 severity_count = defaultdict(int) status_count = defaultdict(int) alert_response = list() if len(alerts) > 0: last_time = None for alert in alerts: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url.replace( 'alerts', 'alert'), alert.id) found += 1