= 11) { $processes[] = [ 'user' => $parts[0], 'pid' => $parts[1], 'pidEncrypted' => encryptString($parts[1]), 'cpu' => $parts[2], 'mem' => $parts[3], 'runtime' => $parts[9], 'command' => $parts[10], ]; } } // Get memory usage $memOutput = []; exec("free -m", $memOutput); preg_match('/^Mem:\s+(\d+)\s+(\d+)\s+/', $memOutput[1], $memMatches); $totalMem = isset($memMatches[1]) ? $memMatches[1] : 0; $usedMem = isset($memMatches[2]) ? $memMatches[2] : 0; $memUsagePercent = $totalMem > 0 ? round(($usedMem / $totalMem) * 100, 2) : 0; // Get CPU usage $cpuOutput = []; exec("top -bn1 | grep 'Cpu(s)'", $cpuOutput); preg_match('/(\d+\.\d+)\s+id/', $cpuOutput[0], $cpuMatches); $cpuIdle = isset($cpuMatches[1]) ? $cpuMatches[1] : 100; $cpuUsagePercent = 100 - $cpuIdle; return [ 'totalCPU' => $cpuUsagePercent, 'totalMem' => $memUsagePercent, 'processes' => $processes ]; } // Handle AJAX requests if (isset($_GET['action']) && $_GET['action'] === 'fetch') { header('Content-Type: application/json'); echo json_encode(getFfmpegProcesses()); exit; } // Handle kill process request securely if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['pid'], $_POST['csrf_token'])) { if (hash_equals($csrfToken, $_POST['csrf_token'])) { $pidDecrypted = decryptString($_POST['pid']); $pid = intval($pidDecrypted); if ($pid > 0) { $command = "kill -9 $pid"; $output = []; $return_var = 0; // Execute the command and capture the output and return status exec($command . " 2>&1", $output, $return_var); // Prepare the response JSON with detailed information echo json_encode([ 'error' => $return_var !== 0, 'msg' => $return_var === 0 ? 'Process killed successfully.' : 'Failed to kill the process.', 'command' => $command, 'output' => $output ]); exit; } } echo json_encode(['error' => true, 'msg' => 'Invalid request.']); exit; } ?>

FFmpeg Monitor

CPU Usage

RAM Usage

Historical Resource Usage