From e4e51365d05d957970e46c0c8f7d98819ec8b04c Mon Sep 17 00:00:00 2001 From: ImBenji Date: Wed, 20 Aug 2025 09:24:43 +0100 Subject: [PATCH] Refactor server status retrieval to focus on active connections only, removing CPU and memory metrics --- lib/services/supabase_heartbeat.dart | 45 +--------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/lib/services/supabase_heartbeat.dart b/lib/services/supabase_heartbeat.dart index 5cffea7..db25971 100644 --- a/lib/services/supabase_heartbeat.dart +++ b/lib/services/supabase_heartbeat.dart @@ -45,7 +45,7 @@ void initHeartbeat() { // Generate operational rolling code for heartbeat authentication String authCode = RollingCodesService.generateOperationalCode(); - // Get server status (CPU, memory, active connections) + // Get basic server status (only active connections) Map serverStatus = await _getServerStatus(); // Send heartbeat to server-manager endpoint @@ -124,12 +124,7 @@ Future _registerInHeartbeatIsolate() async { } Future> _getServerStatus() async { - // Get basic server status information - // This is a simplified implementation - could be enhanced with actual metrics - int activeConnections = 0; - double cpuUsage = 0.0; - double memoryUsage = 0.0; try { // Get active WireGuard connections count @@ -143,45 +138,7 @@ Future> _getServerStatus() async { print("Error getting WireGuard status: $e"); } - try { - // Get basic system info (simplified) - ProcessResult uptimeResult = await Process.run('uptime', []); - if (uptimeResult.exitCode == 0) { - String output = uptimeResult.stdout as String; - // Parse load average as a rough CPU usage indicator - RegExp loadRegex = RegExp(r'load average: (\d+\.?\d*),'); - Match? match = loadRegex.firstMatch(output); - if (match != null) { - cpuUsage = double.tryParse(match.group(1) ?? '0') ?? 0.0; - cpuUsage = (cpuUsage * 100).clamp(0, 100); // Convert to percentage - } - } - } catch (e) { - print("Error getting CPU usage: $e"); - } - - try { - // Get memory usage (simplified) - ProcessResult freeResult = await Process.run('free', ['-m']); - if (freeResult.exitCode == 0) { - String output = freeResult.stdout as String; - List lines = output.split('\n'); - if (lines.length > 1) { - List memLine = lines[1].split(RegExp(r'\s+')); - if (memLine.length > 2) { - int total = int.tryParse(memLine[1]) ?? 1; - int used = int.tryParse(memLine[2]) ?? 0; - memoryUsage = (used / total * 100).clamp(0, 100); - } - } - } - } catch (e) { - print("Error getting memory usage: $e"); - } - return { 'active_connections': activeConnections, - 'cpu_usage': cpuUsage, - 'memory_usage': memoryUsage, }; } \ No newline at end of file