fix: adjust uptime and downtime calculations to prevent division by zero
This commit is contained in:
1 parent
6bd5e9d725
commit
94d643dddf
1 file changed
+4
-3
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user