Fix: Improve uptime monitoring dashboard performance

- Reduce refetch intervals, increase stale times, and optimize retry behavior for uptime service and server metrics.
This commit is contained in:
Tola Leng
2025-07-17 17:26:17 +07:00
parent b9cdff37d5
commit 6906a65952
9 changed files with 367 additions and 330 deletions
@@ -3,13 +3,13 @@ import { pb } from '@/lib/pocketbase';
import { monitoringIntervals } from '../monitoringIntervals';
/**
* Start monitoring for a specific service
* Start monitoring for a specific service with optimized performance
*/
export async function startMonitoringService(serviceId: string): Promise<void> {
try {
// First check if the service is already being monitored
if (monitoringIntervals.has(serviceId)) {
// console.log(`Service ${serviceId} is already being monitored`);
// console.log(`Service ${serviceId} is already being monitored`);
return;
}
@@ -22,7 +22,7 @@ export async function startMonitoringService(serviceId: string): Promise<void> {
return;
}
// console.log(`Starting monitoring for service ${serviceId} (${service.name})`);
// console.log(`Starting optimized monitoring for service ${serviceId} (${service.name})`);
// Update the service status to active/up in the database
await pb.collection('services').update(serviceId, {
@@ -30,20 +30,24 @@ export async function startMonitoringService(serviceId: string): Promise<void> {
});
// The actual service checking is now handled by the Go microservice
// This frontend service just tracks the monitoring state
const intervalMs = (service.heartbeat_interval || 60) * 1000;
// console.log(`Service ${service.name} monitoring delegated to backend service`);
// This frontend service just tracks the monitoring state with much less frequency
const intervalMs = Math.max((service.heartbeat_interval || 60) * 1000, 60000); // Minimum 1 minute
// console.log(`Service ${service.name} monitoring delegated to backend service with interval ${intervalMs}ms`);
// Store a placeholder interval to track that this service is being monitored
// Significantly reduce frequency to prevent excessive logging and CPU usage
const intervalId = window.setInterval(() => {
// console.log(`Monitoring active for service ${service.name} (handled by backend)`);
}, intervalMs);
// Only log every 5 minutes to reduce console spam
if (Date.now() % (5 * 60 * 1000) < intervalMs) {
// console.log(`Monitoring active for service ${service.name} (handled by backend)`);
}
}, Math.max(intervalMs, 300000)); // Minimum 5 minutes for logging
// Store the interval ID for this service
monitoringIntervals.set(serviceId, intervalId);
// console.log(`Monitoring registered for service ${serviceId}`);
// console.log(`Optimized monitoring registered for service ${serviceId}`);
} catch (error) {
// console.error("Error starting service monitoring:", error);
// console.error("Error starting service monitoring:", error);
}
}