fix: stale dasboard ping issue

This commit is contained in:
nate 2026-03-28 16:10:20 +04:00
parent d844b495b2
commit e82a9e92f8
4 changed files with 8 additions and 7 deletions

View File

@ -478,13 +478,11 @@
// ── Interactive latency chart ────────────────────────────────────── // ── Interactive latency chart ──────────────────────────────────────
const REGION_COLORS = { const REGION_COLORS = {
'eu-central': '#3b82f6', 'eu-central': '#3b82f6',
'eu-west': '#8b5cf6',
'us-west': '#f59e0b', 'us-west': '#f59e0b',
'__none__': '#6b7280' '__none__': '#6b7280'
}; };
const REGION_LABELS = { const REGION_LABELS = {
'eu-central': 'EU Central', 'eu-central': 'EU Central',
'eu-west': 'EU West',
'us-west': 'US West' 'us-west': 'US West'
}; };
@ -793,7 +791,7 @@
if (regions.length > 0) { if (regions.length > 0) {
html += '<div class="mt-1.5 pt-1.5 border-t border-gray-700/50">'; html += '<div class="mt-1.5 pt-1.5 border-t border-gray-700/50">';
for (const r of regions) { 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 ? '<span class="text-green-400">Up</span>' : '<span class="text-red-400">Down</span>'; const status = r.up ? '<span class="text-green-400">Up</span>' : '<span class="text-red-400">Down</span>';
const lat = r.latency_ms != null ? `<span class="text-gray-400 font-mono">${r.latency_ms}ms</span>` : ''; const lat = r.latency_ms != null ? `<span class="text-gray-400 font-mono">${r.latency_ms}ms</span>` : '';
html += `<div class="flex items-center justify-between gap-3"><span>${rLabel}</span><span>${lat} ${status}</span></div>`; html += `<div class="flex items-center justify-between gap-3"><span>${rLabel}</span><span>${lat} ${status}</span></div>`;

View File

@ -30,6 +30,7 @@
<% it.monitors.forEach(function(m) { <% it.monitors.forEach(function(m) {
const latencies = (m.pings || []).filter(p => p.latency_ms != null); const latencies = (m.pings || []).filter(p => p.latency_ms != null);
// Pick the region with the lowest avg latency (same logic as sparklineFromPings) // 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 = {}; const byRegion = {};
for (const p of latencies) { for (const p of latencies) {
const key = p.region || '__none__'; const key = p.region || '__none__';
@ -38,7 +39,8 @@
} }
let bestRegion = '__none__', bestAvg = Infinity; let bestRegion = '__none__', bestAvg = Infinity;
for (const [region, vals] of Object.entries(byRegion)) { 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; } if (avg < bestAvg) { bestAvg = avg; bestRegion = region; }
} }
const bestVals = byRegion[bestRegion] || []; const bestVals = byRegion[bestRegion] || [];
@ -115,7 +117,8 @@
let bestRegion = '__none__', bestAvg = Infinity; let bestRegion = '__none__', bestAvg = Infinity;
for (const [region, vals] of Object.entries(regions)) { for (const [region, vals] of Object.entries(regions)) {
if (!vals.length) continue; 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; } if (avg < bestAvg) { bestAvg = avg; bestRegion = region; }
} }
const vals = (regions[bestRegion] || []); const vals = (regions[bestRegion] || []);

View File

@ -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 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 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 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 curMethod = monitor.method || 'GET';
const bodyHidden = ['GET','HEAD','OPTIONS'].includes(curMethod); const bodyHidden = ['GET','HEAD','OPTIONS'].includes(curMethod);
%> %>

View File

@ -12,7 +12,7 @@ SSH="ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519"
DB_HOST="root@142.132.190.209" DB_HOST="root@142.132.190.209"
API_HOST="root@88.99.123.102" API_HOST="root@88.99.123.102"
WEB_HOST="root@78.47.43.36" 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() { deploy_db() {
echo "[db] Restarting PostgreSQL on database-eu-central..." echo "[db] Restarting PostgreSQL on database-eu-central..."