feat: enhance connectivity monitoring with detailed outage logging
This commit is contained in:
1 parent
015c534f97
commit
90772263c1
1 file changed
+28
-2
@@ -220,25 +220,51 @@ function checkConnectivity(url) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let internetDown = false;
|
||||||
|
|
||||||
async function monitor() {
|
async function monitor() {
|
||||||
|
const changed = [];
|
||||||
|
|
||||||
await Promise.all(targets.map(async (t) => {
|
await Promise.all(targets.map(async (t) => {
|
||||||
const online = await checkConnectivity(t.url);
|
const online = await checkConnectivity(t.url);
|
||||||
if (!online && t.isOnline) {
|
if (!online && t.isOnline) {
|
||||||
t.isOnline = false;
|
t.isOnline = false;
|
||||||
t.outageStart = Date.now();
|
t.outageStart = Date.now();
|
||||||
throttledLog(t.id, 'disc', `${t.label} DISCONNECTED`);
|
changed.push({ t, event: 'disc' });
|
||||||
saveState();
|
saveState();
|
||||||
} else if (online && !t.isOnline) {
|
} else if (online && !t.isOnline) {
|
||||||
const end = Date.now();
|
const end = Date.now();
|
||||||
const duration = end - t.outageStart;
|
const duration = end - t.outageStart;
|
||||||
t.totalDowntimeMs += duration;
|
t.totalDowntimeMs += duration;
|
||||||
t.outages.push({ start: t.outageStart, end, duration });
|
t.outages.push({ start: t.outageStart, end, duration });
|
||||||
throttledLog(t.id, 'rest', `${t.label} RESTORED (outage: ${formatDuration(duration)})`);
|
|
||||||
t.isOnline = true;
|
t.isOnline = true;
|
||||||
t.outageStart = null;
|
t.outageStart = null;
|
||||||
|
changed.push({ t, event: 'rest', duration });
|
||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (changed.length === 0) return;
|
||||||
|
|
||||||
|
const allDown = targets.length > 0 && targets.every(t => !t.isOnline);
|
||||||
|
const allUp = targets.length > 0 && targets.every(t => t.isOnline);
|
||||||
|
|
||||||
|
if (allDown && !internetDown) {
|
||||||
|
internetDown = true;
|
||||||
|
console.log(`[${new Date().toISOString()}] INTERNET DOWN`);
|
||||||
|
} else if (allUp && internetDown) {
|
||||||
|
internetDown = false;
|
||||||
|
console.log(`[${new Date().toISOString()}] INTERNET RESTORED`);
|
||||||
|
} else {
|
||||||
|
// Partial change — log per target, but skip targets that are part of an ongoing internet outage
|
||||||
|
for (const { t, event, duration } of changed) {
|
||||||
|
if (event === 'disc' && !internetDown) {
|
||||||
|
throttledLog(t.id, 'disc', `${t.label} DISCONNECTED`);
|
||||||
|
} else if (event === 'rest' && !internetDown) {
|
||||||
|
throttledLog(t.id, 'rest', `${t.label} RESTORED (outage: ${formatDuration(duration)})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDuration(ms) {
|
function formatDuration(ms) {
|
||||||
|
|||||||
Reference in new issue
Block a user