From e82a9e92f8c224665a1dea3a09220bd24ffa2e5a Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 28 Mar 2026 16:10:20 +0400 Subject: [PATCH] fix: stale dasboard ping issue --- apps/web/src/views/detail.ejs | 4 +--- apps/web/src/views/home.ejs | 7 +++++-- apps/web/src/views/partials/monitor-form.ejs | 2 +- deploy.sh | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/src/views/detail.ejs b/apps/web/src/views/detail.ejs index dcc2ddd..57b7b83 100644 --- a/apps/web/src/views/detail.ejs +++ b/apps/web/src/views/detail.ejs @@ -478,13 +478,11 @@ // ── Interactive latency chart ────────────────────────────────────── const REGION_COLORS = { 'eu-central': '#3b82f6', - 'eu-west': '#8b5cf6', 'us-west': '#f59e0b', '__none__': '#6b7280' }; const REGION_LABELS = { 'eu-central': 'EU Central', - 'eu-west': 'EU West', 'us-west': 'US West' }; @@ -793,7 +791,7 @@ if (regions.length > 0) { html += '
'; for (const r of regions) { - const rLabel = {'eu-central':'EU Central','eu-west':'EU West','us-west':'US West'}[r.region] || r.region || 'unknown'; + const rLabel = {'eu-central':'EU Central','us-west':'US West'}[r.region] || r.region || 'unknown'; const status = r.up ? 'Up' : 'Down'; const lat = r.latency_ms != null ? `${r.latency_ms}ms` : ''; html += `
${rLabel}${lat} ${status}
`; diff --git a/apps/web/src/views/home.ejs b/apps/web/src/views/home.ejs index cf8faff..92e166b 100644 --- a/apps/web/src/views/home.ejs +++ b/apps/web/src/views/home.ejs @@ -30,6 +30,7 @@ <% it.monitors.forEach(function(m) { const latencies = (m.pings || []).filter(p => p.latency_ms != null); // Pick the region with the lowest avg latency (same logic as sparklineFromPings) + // Only consider the 3 most recent pings per region to pick best region const byRegion = {}; for (const p of latencies) { const key = p.region || '__none__'; @@ -38,7 +39,8 @@ } let bestRegion = '__none__', bestAvg = Infinity; for (const [region, vals] of Object.entries(byRegion)) { - const avg = vals.reduce((a, b) => a + b, 0) / vals.length; + const recent = vals.slice(-3); + const avg = recent.reduce((a, b) => a + b, 0) / recent.length; if (avg < bestAvg) { bestAvg = avg; bestRegion = region; } } const bestVals = byRegion[bestRegion] || []; @@ -115,7 +117,8 @@ let bestRegion = '__none__', bestAvg = Infinity; for (const [region, vals] of Object.entries(regions)) { if (!vals.length) continue; - const avg = vals.reduce((a, b) => a + b, 0) / vals.length; + const recent = vals.slice(-3); + const avg = recent.reduce((a, b) => a + b, 0) / recent.length; if (avg < bestAvg) { bestAvg = avg; bestRegion = region; } } const vals = (regions[bestRegion] || []); diff --git a/apps/web/src/views/partials/monitor-form.ejs b/apps/web/src/views/partials/monitor-form.ejs index c512df9..5fb50fd 100644 --- a/apps/web/src/views/partials/monitor-form.ejs +++ b/apps/web/src/views/partials/monitor-form.ejs @@ -12,7 +12,7 @@ const allIntervals = [['2','2 seconds'],['5','5 seconds'],['10','10 seconds'],['20','20 seconds'],['30','30 seconds'],['60','1 minute'],['300','5 minutes'],['600','10 minutes'],['1800','30 minutes'],['3600','1 hour']]; const intervals = allIntervals.filter(([val]) => Number(val) >= minInterval); const timeouts = [['5000','5 seconds'],['10000','10 seconds'],['20000','20 seconds'],['30000','30 seconds'],['40000','40 seconds'],['50000','50 seconds'],['60000','60 seconds']]; - const regions = [['eu-central','EU Central'],['eu-west','EU West'],['us-west','US West']]; + const regions = [['eu-central','EU Central'],['us-west','US West']]; const curMethod = monitor.method || 'GET'; const bodyHidden = ['GET','HEAD','OPTIONS'].includes(curMethod); %> diff --git a/deploy.sh b/deploy.sh index ca7a023..dea7c56 100755 --- a/deploy.sh +++ b/deploy.sh @@ -12,7 +12,7 @@ SSH="ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519" DB_HOST="root@142.132.190.209" API_HOST="root@88.99.123.102" WEB_HOST="root@78.47.43.36" -MONITOR_HOSTS=("root@5.78.178.12" "root@49.13.118.44" "root@104.156.253.51" "root@95.179.134.78") +MONITOR_HOSTS=("root@5.78.178.12" "root@49.13.118.44") deploy_db() { echo "[db] Restarting PostgreSQL on database-eu-central..."