first commit
This commit is contained in:
26
backend/app/routes/realtime.py
Normal file
26
backend/app/routes/realtime.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.services.realtime import RealtimeService
|
||||
from app.utils.serialization import to_plain
|
||||
|
||||
realtime_blueprint = Blueprint("realtime", __name__)
|
||||
service = RealtimeService()
|
||||
|
||||
|
||||
@realtime_blueprint.get("/realtime/snapshot")
|
||||
def realtime_snapshot():
|
||||
return jsonify(to_plain(service.snapshot()))
|
||||
|
||||
|
||||
@realtime_blueprint.get("/realtime/history")
|
||||
def realtime_history():
|
||||
range_key = request.args.get("range", "6h")
|
||||
start = request.args.get("start")
|
||||
end = request.args.get("end")
|
||||
metrics = [item.strip() for item in request.args.get("metrics", "").split(",") if item.strip()]
|
||||
try:
|
||||
return jsonify(to_plain(service.history(range_key=range_key, start=start, end=end, metric_ids=metrics or None)))
|
||||
except ValueError as exc:
|
||||
return jsonify({"detail": str(exc)}), 400
|
||||
Reference in New Issue
Block a user