fix(heartbeat): 移除空格對齊,改用直接排版避免 Telegram 跑版
Telegram HTML 模式不渲染等寬字型,空格對齊無效。 改成不對齊但清晰的格式,每行直接顯示 label + value。 2026-04-12 ogt Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -429,7 +429,8 @@ def report_to_telegram_html(report: HeartbeatReport) -> str:
|
||||
"""
|
||||
將 HeartbeatReport 轉換為 Telegram HTML 格式
|
||||
|
||||
一條訊息,包含所有探測結果。
|
||||
使用 <code> 區塊包住需要對齊的內容,確保等寬字型渲染正確。
|
||||
2026-04-12 ogt — 修正 Telegram 空格對齊跑版問題
|
||||
"""
|
||||
ts = report.timestamp.strftime("%Y-%m-%d %H:%M (台北)")
|
||||
|
||||
@@ -443,18 +444,18 @@ def report_to_telegram_html(report: HeartbeatReport) -> str:
|
||||
lines.append("🤖 <b>AI 服務</b>")
|
||||
ollama_probe = report.ai_services.get("ollama", ProbeResult(False, "❌ 無回應"))
|
||||
latency_str = f" ({ollama_probe.latency_ms:.0f}ms)" if ollama_probe.latency_ms else ""
|
||||
lines.append(f" Ollama: {ollama_probe.status}{latency_str}")
|
||||
lines.append(f"Ollama {ollama_probe.status}{latency_str}")
|
||||
|
||||
# 各模型狀態(縮排顯示)
|
||||
for model, loaded in report.ollama_models.items():
|
||||
icon = "✅" if loaded else "❌"
|
||||
short = model.split(":")[0]
|
||||
lines.append(f" {icon} {html.escape(short)}")
|
||||
lines.append(f" {icon} {html.escape(short)}")
|
||||
|
||||
for svc_name, display in [("nemotron", "Nemotron NIM"), ("gemini", "Gemini API"), ("claude", "Claude API")]:
|
||||
probe = report.ai_services.get(svc_name, ProbeResult(False, "❌ 無回應"))
|
||||
latency_str = f" ({probe.latency_ms:.0f}ms)" if probe.latency_ms else ""
|
||||
lines.append(f" {display:<18}{probe.status}{latency_str}")
|
||||
lines.append(f"{display} {probe.status}{latency_str}")
|
||||
|
||||
lines.append("")
|
||||
|
||||
@@ -468,24 +469,24 @@ def report_to_telegram_html(report: HeartbeatReport) -> str:
|
||||
}
|
||||
for key, display in mcp_display.items():
|
||||
probe = report.mcp_providers.get(key, ProbeResult(False, "❌ 無回應"))
|
||||
lines.append(f" {display:<18}{probe.status}")
|
||||
lines.append(f"{display} {probe.status}")
|
||||
|
||||
lines.append("")
|
||||
|
||||
# --- 飛輪狀態 ---
|
||||
fw = report.flywheel
|
||||
lines.append("🔄 <b>飛輪狀態(24h)</b>")
|
||||
lines.append(f" Playbooks: {fw.playbook_count} 個")
|
||||
lines.append(f"Playbooks: {fw.playbook_count} 個")
|
||||
if fw.attempt_24h > 0:
|
||||
rate = int(fw.success_24h / fw.attempt_24h * 100)
|
||||
lines.append(f" 今日修復: {fw.success_24h}/{fw.attempt_24h} 次 ({rate}%)")
|
||||
lines.append(f"今日修復: {fw.success_24h}/{fw.attempt_24h} 次 ({rate}%)")
|
||||
else:
|
||||
lines.append(f" 今日修復: 0 次")
|
||||
lines.append("今日修復: 0 次")
|
||||
if fw.km_total > 0:
|
||||
vec_rate = int(fw.km_vectorized / fw.km_total * 100)
|
||||
lines.append(f" KM 向量化: {fw.km_vectorized}/{fw.km_total} ({vec_rate}%)")
|
||||
lines.append(f"KM 向量化: {fw.km_vectorized}/{fw.km_total} ({vec_rate}%)")
|
||||
if fw.last_learning_at:
|
||||
lines.append(f" 最後學習固化: {fw.last_learning_at.strftime('%H:%M')}")
|
||||
lines.append(f"最後學習固化: {fw.last_learning_at.strftime('%H:%M')}")
|
||||
|
||||
lines.append("")
|
||||
|
||||
@@ -493,15 +494,15 @@ def report_to_telegram_html(report: HeartbeatReport) -> str:
|
||||
lines.append("🚀 <b>基礎設施</b>")
|
||||
argocd = report.infra.get("argocd_sync", ProbeResult(False, "❌ 無回應"))
|
||||
velero = report.infra.get("velero", ProbeResult(False, "❌ 無回應"))
|
||||
lines.append(f" ArgoCD: {argocd.status}")
|
||||
lines.append(f" Velero 備份: {velero.status}")
|
||||
lines.append(f"ArgoCD: {argocd.status}")
|
||||
lines.append(f"Velero 備份: {velero.status}")
|
||||
|
||||
# --- Warnings ---
|
||||
if report.warnings:
|
||||
lines.append("")
|
||||
lines.append(f"⚠️ <b>需關注({len(report.warnings)} 項)</b>")
|
||||
for w in report.warnings:
|
||||
lines.append(f" - {html.escape(w)}")
|
||||
lines.append(f"- {html.escape(w)}")
|
||||
else:
|
||||
lines.append("")
|
||||
lines.append("✅ <b>全部正常</b>")
|
||||
|
||||
Reference in New Issue
Block a user