Refactor server status retrieval to focus on active connections only, removing CPU and memory metrics
This commit is contained in:
@@ -45,7 +45,7 @@ void initHeartbeat() {
|
|||||||
// Generate operational rolling code for heartbeat authentication
|
// Generate operational rolling code for heartbeat authentication
|
||||||
String authCode = RollingCodesService.generateOperationalCode();
|
String authCode = RollingCodesService.generateOperationalCode();
|
||||||
|
|
||||||
// Get server status (CPU, memory, active connections)
|
// Get basic server status (only active connections)
|
||||||
Map<String, dynamic> serverStatus = await _getServerStatus();
|
Map<String, dynamic> serverStatus = await _getServerStatus();
|
||||||
|
|
||||||
// Send heartbeat to server-manager endpoint
|
// Send heartbeat to server-manager endpoint
|
||||||
@@ -124,12 +124,7 @@ Future<void> _registerInHeartbeatIsolate() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> _getServerStatus() async {
|
Future<Map<String, dynamic>> _getServerStatus() async {
|
||||||
// Get basic server status information
|
|
||||||
// This is a simplified implementation - could be enhanced with actual metrics
|
|
||||||
|
|
||||||
int activeConnections = 0;
|
int activeConnections = 0;
|
||||||
double cpuUsage = 0.0;
|
|
||||||
double memoryUsage = 0.0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get active WireGuard connections count
|
// Get active WireGuard connections count
|
||||||
@@ -143,45 +138,7 @@ Future<Map<String, dynamic>> _getServerStatus() async {
|
|||||||
print("Error getting WireGuard status: $e");
|
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<String> lines = output.split('\n');
|
|
||||||
if (lines.length > 1) {
|
|
||||||
List<String> 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 {
|
return {
|
||||||
'active_connections': activeConnections,
|
'active_connections': activeConnections,
|
||||||
'cpu_usage': cpuUsage,
|
|
||||||
'memory_usage': memoryUsage,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user