feat(web): Metrics Strip 自動處置率 + MTTR 真實計算
Some checks failed
E2E Health Check / e2e-health (push) Successful in 17s
CD Pipeline / build-and-deploy (push) Has been cancelled

- autoRemediationRate: resolved+closed / total incidents
- mttrAvg: 平均 (updated_at - created_at) 分鐘/小時
- 替換原本的 '--' 靜態值

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-02 13:03:20 +08:00
parent 05cd9cbab4
commit 1123eb4107

View File

@@ -43,6 +43,26 @@ export default function Home({ params }: { params: { locale: string } }) {
enablePolling: true,
})
// Metrics Strip 計算
const autoRemediationRate = (() => {
if (!incidents || incidents.length === 0) return '--'
const resolved = incidents.filter(i => i.status === 'resolved' || i.status === 'closed').length
if (resolved === 0) return '0%'
return `${((resolved / incidents.length) * 100).toFixed(0)}%`
})()
const mttrAvg = (() => {
if (!incidents || incidents.length === 0) return '--'
const resolved = incidents.filter(i => i.updated_at && (i.status === 'resolved' || i.status === 'closed'))
if (resolved.length === 0) return '--'
const avgMs = resolved.reduce((sum, i) => {
return sum + (new Date(i.updated_at).getTime() - new Date(i.created_at).getTime())
}, 0) / resolved.length
const mins = Math.round(avgMs / 60000)
if (mins < 60) return `${mins}m`
return `${(mins / 60).toFixed(1)}h`
})()
return (
<AppLayout locale={locale} showBackground={false}>
<div style={{
@@ -69,8 +89,8 @@ export default function Home({ params }: { params: { locale: string } }) {
{ label: tDashboard('activeIncidents'), value: incidents?.length ?? '--', sub: incidents?.filter((i) => i.severity === 'P0').length ? `+${incidents.filter((i) => i.severity === 'P0').length} P0` : tDashboard('stable') },
{ label: tDashboard('serviceHealth'), value: `${pulseMetrics?.length ?? '--'}/${pulseMetrics?.length ?? '--'}`, sub: tDashboard('normal') },
{ label: tDashboard('todayIncidents'), value: incidents?.length ?? '--', sub: '' },
{ label: tDashboard('autoRemediationRate'), value: '--', sub: '' },
{ label: tDashboard('mttrAvg'), value: '--', sub: '' },
{ label: tDashboard('autoRemediationRate'), value: autoRemediationRate, sub: '' },
{ label: tDashboard('mttrAvg'), value: mttrAvg, sub: '' },
].map((m, i, arr) => (
<div key={i} style={{
flex: 1,