数据统计页:多机 KPI 对比与余额曲线采样。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -35,6 +35,7 @@ from lib.bridge_client_lib import (
|
||||
post_cond_exit,
|
||||
pull_all_enabled,
|
||||
)
|
||||
from lib.cash_sample_lib import record_cash_samples_from_overview
|
||||
from lib.db_lib import init_db
|
||||
from lib.env_lib import apply_env_updates, env_get
|
||||
from lib.health_watch_lib import inspect_overview_rows
|
||||
@@ -46,6 +47,7 @@ from lib.instances_lib import (
|
||||
update_instance,
|
||||
)
|
||||
from lib.sso_lib import build_embed_open_url
|
||||
from lib.stats_agg_lib import build_stats_curve, build_stats_summary, normalize_window
|
||||
from lib.wechat_lib import (
|
||||
hub_alert_cooldown_sec,
|
||||
hub_health_fail_threshold,
|
||||
@@ -130,6 +132,32 @@ def dashboard():
|
||||
return render_template("dashboard.html")
|
||||
|
||||
|
||||
@app.route("/stats")
|
||||
@login_required
|
||||
def stats_page():
|
||||
return render_template("stats.html")
|
||||
|
||||
|
||||
@app.route("/api/stats/summary")
|
||||
@login_required
|
||||
def api_stats_summary():
|
||||
window = normalize_window(request.args.get("window") or "7d")
|
||||
try:
|
||||
return jsonify(build_stats_summary(window))
|
||||
except Exception as e:
|
||||
return jsonify({"ok": False, "msg": str(e) or "统计失败"}), 500
|
||||
|
||||
|
||||
@app.route("/api/stats/curve")
|
||||
@login_required
|
||||
def api_stats_curve():
|
||||
range_key = normalize_window(request.args.get("range") or request.args.get("window") or "7d")
|
||||
try:
|
||||
return jsonify(build_stats_curve(range_key))
|
||||
except Exception as e:
|
||||
return jsonify({"ok": False, "msg": str(e) or "曲线失败"}), 500
|
||||
|
||||
|
||||
@app.route("/instances", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def instances_page():
|
||||
@@ -323,11 +351,12 @@ def _health_pull_interval_sec() -> float:
|
||||
|
||||
|
||||
def _health_watch_loop() -> None:
|
||||
"""后台巡检:即使无人打开总览也会告警."""
|
||||
"""后台巡检:即使无人打开总览也会告警;并采样余额曲线."""
|
||||
while True:
|
||||
try:
|
||||
rows = pull_all_enabled()
|
||||
inspect_overview_rows(rows)
|
||||
record_cash_samples_from_overview(rows)
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(_health_pull_interval_sec())
|
||||
|
||||
Reference in New Issue
Block a user