login($ssh_username, $ssh_password)) { die('SSH login failed'); } function getDiskData($ssh, $device) { return $ssh->exec("df -h $device"); } function getSystemData($ssh) { // Get memory info using awk to clean up the output $meminfo = $ssh->exec("free -m | awk 'NR==2{printf \"%s,%s,%s,\", $2,$3,$7} NR==3{printf \"%s,%s,%s\", $2,$3,$4}'"); // Use vmstat to get CPU idle percentage, more reliable and commonly available $cpuIdle = $ssh->exec("vmstat 1 2 | tail -1 | awk '{print $15}'"); return [ 'storage' => [ 'system' => parseDiskData($ssh->exec('df -h /dev/ubuntu-vg/ubuntu-lv')), 'data' => parseDiskData($ssh->exec('df -h /dev/sdb1')) ], 'raid' => parseRaidStatus($ssh->exec('cat /proc/mdstat')), 'resources' => parseSystemStats($cpuIdle, $meminfo), 'lastUpdate' => date('Y-m-d H:i:s') ]; } $systemData = getSystemData($ssh); $monitors = [ [ 'id' => 'SystemDisk', 'title' => 'System Disk (sda)', 'icon' => 'hdd', 'color' => 'primary', 'type' => 'storage', 'source' => 'system' ], [ 'id' => 'DataDisk', 'title' => 'Data Disk (sdb)', 'icon' => 'hdd', 'color' => 'primary', 'type' => 'storage', 'source' => 'data' ], [ 'id' => 'RAID', 'title' => 'RAID Status', 'icon' => 'shield-check', 'color' => 'warning', 'type' => 'raid' ], [ 'id' => 'CPU', 'title' => 'CPU Usage', 'icon' => 'cpu', 'color' => 'info', 'type' => 'resources', 'source' => 'cpu' ], [ 'id' => 'Memory', 'title' => 'Memory Usage', 'icon' => 'memory', 'color' => 'success', 'type' => 'resources', 'source' => 'memory' ] ]; function parseDiskData($output) { $lines = explode("\n", trim($output)); if (count($lines) < 2) return null; $values = preg_split('/\s+/', trim($lines[1])); return [ 'size' => $values[1] ?? 'N/A', 'used' => $values[2] ?? 'N/A', 'available' => $values[3] ?? 'N/A', 'usage' => $values[4] ?? '0%' ]; } function parseRaidStatus($output) { if (empty($output)) { return [ 'active' => false, 'status' => 'unknown', 'type' => 'N/A' ]; } $status = [ 'active' => false, 'status' => 'unknown', 'type' => 'N/A' ]; $lines = explode("\n", trim($output)); foreach ($lines as $line) { if (preg_match('/active\s+(\w+)/', $line, $matches)) { $status['active'] = true; $status['type'] = $matches[1] ?? 'N/A'; } if (strpos($line, '[UU]') !== false) { $status['status'] = 'healthy'; } elseif (strpos($line, '_') !== false) { $status['status'] = 'degraded'; } } return $status; } function parseSystemStats($cpuOutput, $memOutput) { // Parse CPU stats - convert idle percentage to usage percentage $idlePercent = floatval(trim(str_replace(',', '.', $cpuOutput))); $cpuUsage = 100 - $idlePercent; // Convert idle to usage percentage if (is_nan($cpuUsage) || $cpuUsage < 0 || $cpuUsage > 100) { $cpuUsage = 0; // Default to 0% if parsing fails } $cpu = ['usage' => number_format($cpuUsage, 1)]; // Parse memory stats $parts = explode(',', $memOutput); if (count($parts) >= 6) { $memTotal = intval($parts[0]); $memUsed = intval($parts[1]); $memAvail = intval($parts[2]); $swapTotal = intval($parts[3]); $swapUsed = intval($parts[4]); $swapFree = intval($parts[5]); $memory = [ 'total' => number_format($memTotal / 1024, 2) . 'G', 'used' => number_format($memUsed / 1024, 2) . 'G', 'available' => number_format($memAvail / 1024, 2) . 'G', 'usage' => ($memTotal > 0 ? round(($memUsed / $memTotal) * 100, 1) : 0) . '%', 'swap_total' => number_format($swapTotal / 1024, 2) . 'G', 'swap_used' => number_format($swapUsed / 1024, 2) . 'G', 'swap_free' => number_format($swapFree / 1024, 2) . 'G', 'swap_usage' => ($swapTotal > 0 ? round(($swapUsed / $swapTotal) * 100, 1) : 0) . '%' ]; } else { $memory = [ 'total' => '0G', 'used' => '0G', 'available' => '0G', 'usage' => '0%', 'swap_total' => '0G', 'swap_used' => '0G', 'swap_free' => '0G', 'swap_usage' => '0%' ]; } return ['cpu' => $cpu, 'memory' => $memory]; } function convertToBytes($size) { if (preg_match('/^([\d.]+)([KMGT]?)i?B?$/', trim($size), $matches)) { $value = floatval($matches[1]); $unit = strtoupper($matches[2]); switch ($unit) { case 'P': $value *= 1024; case 'T': $value *= 1024; case 'G': $value *= 1024; case 'M': $value *= 1024; case 'K': $value *= 1024; } return $value; } return 0; } function formatBytes($bytes, $forceUnit = '') { $units = ['B', 'K', 'M', 'G', 'T', 'P']; $bytes = max($bytes, 0); if ($forceUnit) { $unitIndex = array_search($forceUnit, $units); if ($unitIndex !== false) { $bytes /= pow(1024, $unitIndex); return round($bytes, 2) . $forceUnit; } } $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= pow(1024, $pow); return round($bytes, 2) . $units[$pow]; } ?> Server Status

Server Status

Logout Change Password Admin Panel SFTP

Server Disk Status

Storage Usage
Total
Used
Free

Array

Memory Usage
Total
Used
Available
Swap Usage
Total
Used
Free