From a5d3ac08c638e8655e51c852fdd39b541dce9c19 Mon Sep 17 00:00:00 2001 From: boban Date: Tue, 28 Oct 2025 19:27:52 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20Mailbox=20Stats=20=C3=BCber=20Dovecot=20?= =?UTF-8?q?mit=20config/mailpool.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/StorageProbe.php | 19 ----- app/Livewire/Ui/System/StorageCard.php | 74 ++++++++++++++++--- .../livewire/ui/system/storage-card.blade.php | 3 +- 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/app/Console/Commands/StorageProbe.php b/app/Console/Commands/StorageProbe.php index ad3bc1a..040ce7a 100644 --- a/app/Console/Commands/StorageProbe.php +++ b/app/Console/Commands/StorageProbe.php @@ -63,23 +63,6 @@ class StorageProbe extends Command $freePlusReserveGb = min($totalGb, $freeGb + $res5Gb); $percentUsed = $totalGb > 0 ? (int)round($usedGb * 100 / $totalGb) : 0; - // --- du: reale Verbräuche bestimmter Bäume (KB) ----------------------- -// $duKb = function (string $path): int { -// if (!is_dir($path)) return 0; -// $kb = (int)trim((string)@shell_exec('LC_ALL=C du -sk --apparent-size ' . escapeshellarg($path) . ' 2>/dev/null | cut -f1')); -// return max(0, $kb); -// }; -// -// $kbMails = $duKb('/var/mail/vhosts'); -// $kbBackup = $duKb('/var/backups/mailwolt'); -// -// // „System“ = alles übrige, was nicht Mails/Backups ist (OS, App, Logs, DB-Daten, …) -// $gbMails = $toGiB_f($kbMails); -// $gbBackup = $toGiB_f($kbBackup); -// -// // system_gb aus „usedGb – (mails+backup)“, nie negativ -// $gbSystem = max(0, round($usedGb - ($gbMails + $gbBackup), 1)); - $duBytes = function (string $path): int { if (!is_dir($path)) return 0; $b = (int) trim((string) @shell_exec( @@ -91,12 +74,10 @@ class StorageProbe extends Command $bytesMails = $duBytes('/var/mail/vhosts'); $bytesBackup = $duBytes('/var/backups/mailwolt'); -// used_gb in Bytes nachrechnen (aus df) $totalBytes = (int) $totalKb * 1024; $freeBytes = (int) $availKb * 1024; $usedBytes = max(0, $totalBytes - $freeBytes); -// „System“ = Rest $bytesSystem = max(0, $usedBytes - ($bytesMails + $bytesBackup)); return [ diff --git a/app/Livewire/Ui/System/StorageCard.php b/app/Livewire/Ui/System/StorageCard.php index a779a6a..aa1aadd 100644 --- a/app/Livewire/Ui/System/StorageCard.php +++ b/app/Livewire/Ui/System/StorageCard.php @@ -50,6 +50,15 @@ class StorageCard extends Component // ───────────────────────────────────────────────────────────── + private function humanBytes(float|int $bytes): string + { + $b = max(0, (float)$bytes); + if ($b >= 1024 ** 3) return number_format($b / (1024 ** 3), 1) . ' GB'; + if ($b >= 1024 ** 2) return number_format($b / (1024 ** 2), 2) . ' MiB'; + if ($b >= 1024) return number_format($b / 1024, 0) . ' KiB'; + return (string)((int)$b) . ' B'; + } + protected function loadFromSettings(): void { $disk = Setting::get('health.disk', []); @@ -137,11 +146,48 @@ class StorageCard extends Component return $out; } +// protected function buildLegendGbFromBytes(array $bdBytes, int $totalBytes, int $freeBytes): array +// { +// $defs = [ +// ['key' => 'system', 'label' => 'System', 'class' => 'bg-emerald-400'], +// ['key' => 'mails', 'label' => 'Mails', 'class' => 'bg-rose-400'], +// ['key' => 'backup', 'label' => 'Backups', 'class' => 'bg-sky-400'], +// ]; +// +// $toPercent = function (int $bytes) use ($totalBytes): int { +// if ($totalBytes <= 0) return 0; +// return (int)max(0, min(100, round($bytes * 100 / $totalBytes))); +// }; +// $toGb = fn(int $bytes) => round($bytes / (1024 ** 3), 1); +// +// $out = []; +// foreach ($defs as $d) { +// $val = max(0, (int)($bdBytes[$d['key']] ?? 0)); +// if ($val <= 0) continue; // zu klein → nicht anzeigen +// $out[] = [ +// 'label' => $d['label'], +// 'color' => $d['class'], +// 'gb' => $toGb($val), // ← genau das Feld, das dein Blade nutzt +// 'percent' => $toPercent($val), +// ]; +// } +// +// // „Frei“ immer anzeigen +// $out[] = [ +// 'label' => 'Frei', +// 'color' => 'bg-white/20', +// 'gb' => $toGb($freeBytes), +// 'percent' => $toPercent($freeBytes), +// ]; +// +// return $out; +// } + protected function buildLegendGbFromBytes(array $bdBytes, int $totalBytes, int $freeBytes): array { $defs = [ - ['key' => 'system', 'label' => 'System', 'class' => 'bg-emerald-400'], - ['key' => 'mails', 'label' => 'Mails', 'class' => 'bg-rose-400'], + ['key' => 'system', 'label' => 'System', 'class' => 'bg-emerald-400'], + ['key' => 'mails', 'label' => 'Mails', 'class' => 'bg-rose-400'], ['key' => 'backup', 'label' => 'Backups', 'class' => 'bg-sky-400'], ]; @@ -149,31 +195,37 @@ class StorageCard extends Component if ($totalBytes <= 0) return 0; return (int)max(0, min(100, round($bytes * 100 / $totalBytes))); }; - $toGb = fn(int $bytes) => round($bytes / (1024 ** 3), 1); + $toGbNum = fn(int $bytes) => round($bytes / (1024 ** 3), 1); $out = []; + foreach ($defs as $d) { $val = max(0, (int)($bdBytes[$d['key']] ?? 0)); - if ($val <= 0) continue; // zu klein → nicht anzeigen + // < 1 MiB NICHT anzeigen + if ($val <= 0) continue; + $out[] = [ - 'label' => $d['label'], - 'color' => $d['class'], - 'gb' => $toGb($val), // ← genau das Feld, das dein Blade nutzt + 'label' => $d['label'], + 'color' => $d['class'], + // numerisch in GB lassen (falls du später rechnen willst) + 'gb' => $toGbNum($val), 'percent' => $toPercent($val), + // FERTIG formatiert mit Einheit fürs Blade + 'human' => $this->humanBytes($val), ]; } // „Frei“ immer anzeigen $out[] = [ - 'label' => 'Frei', - 'color' => 'bg-white/20', - 'gb' => $toGb($freeBytes), + 'label' => 'Frei', + 'color' => 'bg-white/20', + 'gb' => $toGbNum($freeBytes), 'percent' => $toPercent($freeBytes), + 'human' => $this->humanBytes($freeBytes), ]; return $out; } - protected function resetUi(): void { $this->diskTotalGb = null; diff --git a/resources/views/livewire/ui/system/storage-card.blade.php b/resources/views/livewire/ui/system/storage-card.blade.php index df9e192..5721bc3 100644 --- a/resources/views/livewire/ui/system/storage-card.blade.php +++ b/resources/views/livewire/ui/system/storage-card.blade.php @@ -63,7 +63,8 @@ @foreach($barSegments as $b)
- {{ $b['label'] }} {{ $b['gb'] }} GB ({{ $b['percent'] }}%) + {{ $b['label'] }} {{ $b['human'] }} ({{ $b['percent'] }}%) +{{-- {{ $b['label'] }} {{ $b['gb'] }} GB ({{ $b['percent'] }}%)--}}
@endforeach