diff --git a/apps/web/src/app/[locale]/page.tsx b/apps/web/src/app/[locale]/page.tsx index a3f12afa..bb48daca 100644 --- a/apps/web/src/app/[locale]/page.tsx +++ b/apps/web/src/app/[locale]/page.tsx @@ -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 (
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) => (