@php /** * @api-readonly * System disk usage information */ use Illuminate\Support\Facades\Cache; $result = Cache::remember('system_disk_usage_stats', 3600, function() { // Disk kullanım durumunu topla $diskInfo = []; $directorySizes = []; // Ana disk bilgilerini al $diskUsage = shell_exec('df -h / 2>/dev/null | tail -n 1'); $diskParts = preg_split('/\s+/', trim($diskUsage)); $diskInfo = [ 'filesystem' => $diskParts[0] ?? 'Unknown', 'total_size' => $diskParts[1] ?? '0', 'used' => $diskParts[2] ?? '0', 'available' => $diskParts[3] ?? '0', 'use_percentage' => str_replace('%', '', $diskParts[4] ?? '0'), 'mount_point' => $diskParts[5] ?? '/' ]; // Ana dizinlerin boyutlarını al $directories = [ '/var' => 'var', '/usr' => 'usr', '/root' => 'root', '/opt' => 'opt', '/tmp' => 'tmp', '/boot' => 'boot', '/etc' => 'etc' ]; foreach($directories as $path => $name) { $size = shell_exec("du -sh $path 2>/dev/null | cut -f1"); if($size) { $directorySizes[] = [ 'directory' => $name, 'path' => $path, 'size_text' => trim($size), 'size_bytes' => convertToBytes(trim($size)) ]; } } // /var alt dizinlerini al $varSubDirs = [ '/var/lib' => 'var/lib (Database)', '/var/www' => 'var/www (Web Files)', '/var/log' => 'var/log (Log Files)', '/var/cache' => 'var/cache (Cache)' ]; $varDetails = []; foreach($varSubDirs as $path => $name) { $size = shell_exec("du -sh $path 2>/dev/null | cut -f1"); if($size) { $varDetails[] = [ 'directory' => $name, 'path' => $path, 'size_text' => trim($size), 'size_bytes' => convertToBytes(trim($size)) ]; } } // Web projeleri detayları $webProjects = []; $webPath = '/var/www/html'; if(is_dir($webPath)) { $projects = glob($webPath . '/*', GLOB_ONLYDIR); foreach($projects as $project) { $projectName = basename($project); $size = shell_exec("du -sh '$project' 2>/dev/null | cut -f1"); if($size) { $webProjects[] = [ 'project' => $projectName, 'path' => $project, 'size_text' => trim($size), 'size_bytes' => convertToBytes(trim($size)) ]; } } // Boyuta göre sırala usort($webProjects, function($a, $b) { return $b['size_bytes'] - $a['size_bytes']; }); } // Log dosyaları detayları $logFiles = []; $logPath = '/var/log'; if(is_dir($logPath)) { $logs = shell_exec("du -sh $logPath/* 2>/dev/null | sort -hr | head -10"); if($logs) { $logLines = explode("\n", trim($logs)); foreach($logLines as $line) { if(trim($line)) { $parts = preg_split('/\s+/', trim($line), 2); if(count($parts) >= 2) { $logFiles[] = [ 'file' => basename($parts[1]), 'path' => $parts[1], 'size_text' => $parts[0], 'size_bytes' => convertToBytes($parts[0]) ]; } } } } } // Bellek bilgilerini al $memInfo = shell_exec('free -h | grep Mem'); $memParts = preg_split('/\s+/', trim($memInfo)); $memoryInfo = [ 'total' => $memParts[1] ?? '0', 'used' => $memParts[2] ?? '0', 'free' => $memParts[3] ?? '0', 'shared' => $memParts[4] ?? '0', 'buff_cache' => $memParts[5] ?? '0', 'available' => $memParts[6] ?? '0' ]; // Chart için veri hazırla $chartData = []; foreach($directorySizes as $dir) { if($dir['size_bytes'] > 1000000) { // 1MB'dan büyük olanları göster $chartData[] = [ 'directory' => $dir['directory'], 'size' => round($dir['size_bytes'] / (1024*1024*1024), 2), // GB cinsinden 'percentage' => round(($dir['size_bytes'] / convertToBytes($diskInfo['total_size'])) * 100, 1) ]; } } // /var dizini detaylı analizi $varDetailedAnalysis = []; // MySQL veritabanları detayı $mysqlSize = shell_exec("du -sh /var/lib/mysql 2>/dev/null | cut -f1"); if($mysqlSize) { $varDetailedAnalysis[] = [ 'component' => 'MySQL Databases', 'path' => '/var/lib/mysql', 'size_text' => trim($mysqlSize), 'size_bytes' => convertToBytes(trim($mysqlSize)), 'description' => 'Veritabanı dosyaları' ]; } // Web projeleri detayı $webSize = shell_exec("du -sh /var/www 2>/dev/null | cut -f1"); if($webSize) { $varDetailedAnalysis[] = [ 'component' => 'Web Projects', 'path' => '/var/www', 'size_text' => trim($webSize), 'size_bytes' => convertToBytes(trim($webSize)), 'description' => 'Web sitesi dosyaları' ]; } // Log dosyaları $logSize = shell_exec("du -sh /var/log 2>/dev/null | cut -f1"); if($logSize) { $varDetailedAnalysis[] = [ 'component' => 'System Logs', 'path' => '/var/log', 'size_text' => trim($logSize), 'size_bytes' => convertToBytes(trim($logSize)), 'description' => 'Sistem günlük dosyaları' ]; } // Cache dosyaları $cacheSize = shell_exec("du -sh /var/cache 2>/dev/null | cut -f1"); if($cacheSize) { $varDetailedAnalysis[] = [ 'component' => 'Cache Files', 'path' => '/var/cache', 'size_text' => trim($cacheSize), 'size_bytes' => convertToBytes(trim($cacheSize)), 'description' => 'Önbellek dosyaları' ]; } // /var/lib altında mysql dışındaki dosyalar $libOthersSize = shell_exec("du -sh /var/lib 2>/dev/null | cut -f1"); $libOthersBytes = 0; if($libOthersSize && $mysqlSize) { $libTotalBytes = convertToBytes(trim($libOthersSize)); $mysqlBytes = convertToBytes(trim($mysqlSize)); $libOthersBytes = $libTotalBytes - $mysqlBytes; if($libOthersBytes > 1000000) { // 1MB'dan büyükse ekle $varDetailedAnalysis[] = [ 'component' => 'Other System Data', 'path' => '/var/lib (others)', 'size_text' => formatBytes($libOthersBytes), 'size_bytes' => $libOthersBytes, 'description' => 'Sistem paketleri ve diğer veriler' ]; } } // /var altında diğer klasörler $varOthers = shell_exec("du -sh /var/* 2>/dev/null | grep -v '/var/lib\|/var/www\|/var/log\|/var/cache' | sort -hr"); if($varOthers) { $otherLines = explode("\n", trim($varOthers)); $othersTotalBytes = 0; foreach($otherLines as $line) { if(trim($line)) { $parts = preg_split('/\s+/', trim($line), 2); if(count($parts) >= 2) { $othersTotalBytes += convertToBytes($parts[0]); } } } if($othersTotalBytes > 1000000) { // 1MB'dan büyükse ekle $varDetailedAnalysis[] = [ 'component' => 'Other Directories', 'path' => '/var (others)', 'size_text' => formatBytes($othersTotalBytes), 'size_bytes' => $othersTotalBytes, 'description' => 'Diğer sistem klasörleri' ]; } } // Web Projects Chart Data (sadece /var/www projeleri) $webProjectsChartData = []; foreach($webProjects as $project) { $webProjectsChartData[] = [ 'project' => $project['project'], 'size' => round($project['size_bytes'] / (1024*1024*1024), 2), // GB cinsinden 'percentage' => round(($project['size_bytes'] / convertToBytes(trim($webSize))) * 100, 1), 'description' => 'Web Project' ]; } // System Components Chart Data (MySQL, Logs, Cache, vs.) $systemComponentsData = []; // MySQL if($mysqlSize) { $systemComponentsData[] = [ 'component' => 'MySQL Databases', 'size' => round(convertToBytes(trim($mysqlSize)) / (1024*1024*1024), 2), 'percentage' => round((convertToBytes(trim($mysqlSize)) / convertToBytes('332G')) * 100, 1), 'description' => 'Veritabanı dosyaları', 'color' => '#ff6b6b' ]; } // System Logs if($logSize) { $systemComponentsData[] = [ 'component' => 'System Logs', 'size' => round(convertToBytes(trim($logSize)) / (1024*1024*1024), 2), 'percentage' => round((convertToBytes(trim($logSize)) / convertToBytes('332G')) * 100, 1), 'description' => 'Sistem günlük dosyaları', 'color' => '#4ecdc4' ]; } // Cache Files if($cacheSize) { $systemComponentsData[] = [ 'component' => 'Cache Files', 'size' => round(convertToBytes(trim($cacheSize)) / (1024*1024*1024), 2), 'percentage' => round((convertToBytes(trim($cacheSize)) / convertToBytes('332G')) * 100, 1), 'description' => 'Önbellek dosyaları', 'color' => '#45b7d1' ]; } // Other System Data (var/lib içinde mysql dışı + diğer var klasörleri) $otherSystemBytes = 0; // /var/lib içinde mysql dışı if($libOthersSize && $mysqlSize) { $libTotalBytes = convertToBytes(trim($libOthersSize)); $mysqlBytes = convertToBytes(trim($mysqlSize)); $libOthersBytes = $libTotalBytes - $mysqlBytes; $otherSystemBytes += $libOthersBytes; } // /var altında diğer klasörler (lib, www, log, cache dışı) $varOthers = shell_exec("du -sh /var/* 2>/dev/null | grep -v '/var/lib\|/var/www\|/var/log\|/var/cache' | sort -hr"); if($varOthers) { $otherLines = explode("\n", trim($varOthers)); foreach($otherLines as $line) { if(trim($line)) { $parts = preg_split('/\s+/', trim($line), 2); if(count($parts) >= 2) { $otherSystemBytes += convertToBytes($parts[0]); } } } } if($otherSystemBytes > 1000000) { // 1MB'dan büyükse ekle $systemComponentsData[] = [ 'component' => 'Other System Data', 'size' => round($otherSystemBytes / (1024*1024*1024), 2), 'percentage' => round(($otherSystemBytes / convertToBytes('332G')) * 100, 1), 'description' => 'Sistem paketleri ve diğer klasörler', 'color' => '#96ceb4' ]; } return [ 'success' => true, 'timestamp' => date('Y-m-d H:i:s'), 'disk_info' => $diskInfo, 'directory_sizes' => $directorySizes, 'var_details' => $varDetails, 'var_detailed_analysis' => $varDetailedAnalysis, 'web_projects' => $webProjects, 'log_files' => $logFiles, 'memory_info' => $memoryInfo, 'chart_data' => $chartData, 'web_projects_chart_data' => $webProjectsChartData, 'system_components_chart_data' => $systemComponentsData ]; }); // Bytes'ı human readable'a çeviren fonksiyon function convertToBytes($size) { $size = trim($size); $unit = strtoupper(substr($size, -1)); $value = floatval($size); switch($unit) { case 'K': return $value * 1024; case 'M': return $value * 1024 * 1024; case 'G': return $value * 1024 * 1024 * 1024; case 'T': return $value * 1024 * 1024 * 1024 * 1024; default: return $value; } } // formatBytes() fonksiyonu zaten sistemde mevcut, kullanacağız // Sonucu JSON olarak döndür header('Content-Type: application/json'); echo json_encode($result, JSON_PRETTY_PRINT); @endphp