Skip to content

Commit f92bdf1

Browse files
committed
Ping Debugging
1 parent 023d7f7 commit f92bdf1

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

scripts/check-monitors.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,15 @@ async function checkPing(target, timeout = 10) {
684684
const { stdout } = await execAsync(command, { timeout: (timeout + 2) * 1000 });
685685
const responseTime = Date.now() - startTime;
686686

687+
// Debug logging for ping output
688+
console.log(` [PING DEBUG] Target: ${target}`);
689+
console.log(` [PING DEBUG] Command: ${command}`);
690+
console.log(` [PING DEBUG] Raw stdout:\n${stdout}`);
691+
console.log(` [PING DEBUG] Elapsed time: ${responseTime}ms`);
692+
687693
const lossMatch = stdout.match(/(\d+)%\s*(?:packet\s*)?loss/i);
688694
const packetLoss = lossMatch ? parseInt(lossMatch[1], 10) : null;
695+
console.log(` [PING DEBUG] Packet loss: ${packetLoss}%`);
689696

690697
if (packetLoss === 100) {
691698
return {
@@ -696,21 +703,30 @@ async function checkPing(target, timeout = 10) {
696703
}
697704

698705
let pingTime = null;
706+
let matchedPattern = null;
699707
const patterns = [
700708
/time[=<](\d+\.?\d*)\s*ms/i, // Most common: time=15ms, time=15.3 ms, time<1ms
701709
/time[=<]\s*(\d+\.?\d*)\s*ms/i, // With space after =: time= 15 ms
702710
/rtt\s+min\/avg\/max\/\S+\s*=\s*[\d.]+\/([\d.]+)/i, // Linux summary: rtt min/avg/max/mdev = 14.267/14.267/14.267/0.000 ms
703711
/(\d+\.?\d*)\s*ms\s*$/im // Fallback: just "15.3 ms" at end of line
704712
];
705-
for (const pattern of patterns) {
706-
const match = stdout.match(pattern);
713+
for (let i = 0; i < patterns.length; i++) {
714+
const match = stdout.match(patterns[i]);
707715
if (match) {
708716
pingTime = parseFloat(match[1]);
717+
matchedPattern = i;
718+
console.log(` [PING DEBUG] Matched pattern ${i}: ${patterns[i]}`);
719+
console.log(` [PING DEBUG] Extracted ping time: ${pingTime}ms`);
709720
break;
710721
}
711722
}
712723

724+
if (pingTime === null) {
725+
console.log(` [PING DEBUG] No pattern matched! Using fallback.`);
726+
}
727+
713728
const finalResponseTime = pingTime ?? Math.min(responseTime, timeout * 1000);
729+
console.log(` [PING DEBUG] Final response time: ${finalResponseTime}ms`);
714730

715731
return {
716732
status: 'operational',

0 commit comments

Comments
 (0)