diff --git a/index.js b/index.js index 22f7bd5..20e3b8c 100644 --- a/index.js +++ b/index.js @@ -840,9 +840,10 @@ app.get('/', async (req, res) => { const allOutagesList = d.targets.flatMap(t => t.outages); const avgMs = allOutagesList.length > 0 ? allOutagesList.reduce((s, o) => s + o.duration, 0) / allOutagesList.length : 0; const maxMs = allOutagesList.length > 0 ? Math.max(...allOutagesList.map(o => o.duration)) : 0; - const totalUptimeMs = d.targets.reduce((s, t) => s + t.totalUptimeMs, 0); - const totalDowntimeMs = d.targets.reduce((s, t) => s + t.totalDowntimeMs, 0); - const totalMonitorMs = d.targets.reduce((s, t) => s + t.uptimeMs, 0); + const n = d.targets.length || 1; + const totalUptimeMs = d.targets.reduce((s, t) => s + t.totalUptimeMs, 0) / n; + const totalDowntimeMs = d.targets.reduce((s, t) => s + t.totalDowntimeMs, 0) / n; + const totalMonitorMs = d.targets.reduce((s, t) => s + t.uptimeMs, 0) / n; const uptimePct = totalMonitorMs > 0 ? totalUptimeMs / totalMonitorMs * 100 : 100; const downtimePct = totalMonitorMs > 0 ? totalDowntimeMs / totalMonitorMs * 100 : 0; document.getElementById('stat-uptime').textContent = fmtMs(totalUptimeMs);