diff --git a/routes/admin_observability_routes.py b/routes/admin_observability_routes.py index 0be0aa2..4fa609f 100644 --- a/routes/admin_observability_routes.py +++ b/routes/admin_observability_routes.py @@ -2347,6 +2347,27 @@ def host_health_dashboard(): float(heal_rows[1] or 0) / float(heal_rows[0]) * 100 ) if heal_rows[0] else 0, } + + # Phase 54 R-3: heal 7d daily success rate sparkline + heal_daily = _session2.execute( + sa_text(""" + SELECT date_trunc('day', created_at)::date AS d, + COUNT(*) AS total, + COUNT(*) FILTER (WHERE result = 'success') AS ok + FROM heal_logs + WHERE created_at >= NOW() - INTERVAL '7 days' + GROUP BY d ORDER BY d ASC + """), + ).fetchall() + aiops_summary['heal_sparkline'] = [ + { + 'date': r[0].strftime('%m-%d') if r[0] else '', + 'total': int(r[1] or 0), + 'ok': int(r[2] or 0), + 'rate': (float(r[2] or 0) / float(r[1]) * 100) if r[1] else 0, + } + for r in heal_daily + ] except Exception: aiops_summary = {} diff --git a/templates/admin/ai_calls_dashboard.html b/templates/admin/ai_calls_dashboard.html index c2f2136..9fed29c 100644 --- a/templates/admin/ai_calls_dashboard.html +++ b/templates/admin/ai_calls_dashboard.html @@ -55,14 +55,54 @@ - +
-
呼叫次數

{{ "{:,}".format(summary.total_calls or 0) }}

-
Token 用量

{{ "{:,}".format(summary.total_tokens or 0) }}

-
成本 (USD)

${{ "%.2f"|format(summary.total_cost or 0) }}

-
平均耗時

{{ summary.avg_duration or 0 }} ms

-
RAG 命中

{{ summary.rag_hits or 0 }}

-
錯誤次數

{{ summary.error_calls or 0 }}

+
+
+ 呼叫次數 +

{{ "{:,}".format(summary.total_calls or 0) }}

+ {% if hourly_trend %}{% endif %} +
+
+
+
+ Token 用量 +

{{ "{:,}".format(summary.total_tokens or 0) }}

+ {{ (summary.total_tokens or 0) // (summary.total_calls or 1) }} tk/call 平均 +
+
+
+
+ 成本 (USD) +

${{ "%.2f"|format(summary.total_cost or 0) }}

+ {% if hourly_trend %}{% endif %} +
+
+
+
+ 平均耗時 +

{{ summary.avg_duration or 0 }} ms

+ {{ summary.cache_hits or 0 }} 次 cache 命中 +
+
+
+
+ RAG 命中 +

{{ summary.rag_hits or 0 }}

+ + {% if (summary.total_calls or 0) > 0 %} + {{ "%.1f"|format((summary.rag_hits or 0) / summary.total_calls * 100) }}% + {% else %}—{% endif %} + +
+
+
+
+ 錯誤次數 +

{{ summary.error_calls or 0 }}

+ {% if hourly_trend %}{% endif %} +
+
@@ -268,12 +308,33 @@ + {% endif %} diff --git a/templates/admin/host_health.html b/templates/admin/host_health.html index e5ee49e..f941fe9 100644 --- a/templates/admin/host_health.html +++ b/templates/admin/host_health.html @@ -179,6 +179,14 @@ 7d 共 {{ aiops_summary.heals_total }} 次自癒嘗試 (成功 {{ aiops_summary.heals_success }} · 失敗 {{ aiops_summary.heals_failed }}) + {% if aiops_summary.heal_sparkline %} +
+ +
+
+ 7 日每日自癒成功率趨勢 +
+ {% endif %} {% endif %} @@ -474,7 +482,41 @@

+