fix: latency chart red dots — track up/down with latency values
This commit is contained in:
parent
923f0349dc
commit
d41d3a3737
|
|
@ -224,7 +224,7 @@
|
||||||
// Seed running stats for SSE incremental updates
|
// Seed running stats for SSE incremental updates
|
||||||
_totalPings = results.length;
|
_totalPings = results.length;
|
||||||
_upPings = upPings.length;
|
_upPings = upPings.length;
|
||||||
_latencies = latencies.slice(-100);
|
_latencies = results.filter(r => r.latency_ms != null).slice(-100).map(r => ({ ms: r.latency_ms, up: r.up }));
|
||||||
|
|
||||||
document.getElementById('stat-status').innerHTML = lastPing
|
document.getElementById('stat-status').innerHTML = lastPing
|
||||||
? (lastPing.up ? '<span class="text-green-400">Up</span>' : '<span class="text-red-400">Down</span>')
|
? (lastPing.up ? '<span class="text-green-400">Up</span>' : '<span class="text-red-400">Down</span>')
|
||||||
|
|
@ -361,7 +361,7 @@
|
||||||
// No interval poll — SSE handles all live updates
|
// No interval poll — SSE handles all live updates
|
||||||
|
|
||||||
// Track running stats in memory for incremental updates
|
// Track running stats in memory for incremental updates
|
||||||
let _totalPings = 0, _upPings = 0, _latencies = [];
|
let _totalPings = 0, _upPings = 0, _latencies = []; // _latencies: [{ms, up}]
|
||||||
|
|
||||||
// SSE: live ping updates
|
// SSE: live ping updates
|
||||||
const id = window.location.pathname.split('/').pop();
|
const id = window.location.pathname.split('/').pop();
|
||||||
|
|
@ -370,9 +370,9 @@
|
||||||
_totalPings++;
|
_totalPings++;
|
||||||
if (ping.up) _upPings++;
|
if (ping.up) _upPings++;
|
||||||
if (ping.latency_ms != null) {
|
if (ping.latency_ms != null) {
|
||||||
_latencies.push(ping.latency_ms);
|
_latencies.push({ ms: ping.latency_ms, up: ping.up });
|
||||||
if (_latencies.length > 100) _latencies.shift();
|
if (_latencies.length > 100) _latencies.shift();
|
||||||
const avg = Math.round(_latencies.reduce((a,b)=>a+b,0) / _latencies.length);
|
const avg = Math.round(_latencies.reduce((a,b)=>a+b.ms,0) / _latencies.length);
|
||||||
document.getElementById('stat-latency').textContent = avg + 'ms';
|
document.getElementById('stat-latency').textContent = avg + 'ms';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -398,9 +398,7 @@
|
||||||
|
|
||||||
// ── Latency chart ─────────────────────────────────────────────
|
// ── Latency chart ─────────────────────────────────────────────
|
||||||
if (ping.latency_ms != null) {
|
if (ping.latency_ms != null) {
|
||||||
renderLatencyChart([...(_latencies.map((ms, i) => ({
|
renderLatencyChart(_latencies.map(e => ({ latency_ms: e.ms, up: e.up, checked_at: '' })));
|
||||||
latency_ms: ms, checked_at: new Date(Date.now() - (_latencies.length - i) * 10000).toISOString()
|
|
||||||
})))]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Ping table ───────────────────────────────────────────────
|
// ── Ping table ───────────────────────────────────────────────
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue