修复websocket

This commit is contained in:
CN-JS-HuiBai
2026-04-07 12:20:09 +08:00
parent 73401309f2
commit 307a26c0db
3 changed files with 80 additions and 4 deletions

View File

@@ -1026,7 +1026,34 @@ function broadcast(data) {
async function broadcastMetrics() {
try {
const overview = await getOverview();
broadcast({ type: 'overview', data: overview });
// Also include latencies in the broadcast to make map lines real-time
const [routes] = await db.query(`
SELECT r.*, s.url, s.type as source_type
FROM latency_routes r
JOIN prometheus_sources s ON r.source_id = s.id
`);
const latencyResults = await Promise.all(routes.map(async (route) => {
let latency = await cache.get(`latency:route:${route.id}`);
if (latency === null && route.source_type === 'prometheus') {
latency = await prometheusService.getLatency(route.url, route.latency_target);
}
return {
id: route.id,
source: route.latency_source,
dest: route.latency_dest,
latency: latency
};
}));
broadcast({
type: 'overview',
data: {
...overview,
latencies: latencyResults
}
});
} catch (err) {
// console.error('WS Broadcast error:', err.message);
}