parent
4197b61905
commit
a5d3ac08c6
|
|
@ -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 [
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@
|
|||
@foreach($barSegments as $b)
|
||||
<div class="inline-flex items-center gap-2">
|
||||
<span class="inline-block w-2.5 h-2.5 rounded-full {{ $b['color'] }}"></span>
|
||||
<span>{{ $b['label'] }} {{ $b['gb'] }} GB ({{ $b['percent'] }}%)</span>
|
||||
<span>{{ $b['label'] }} {{ $b['human'] }} ({{ $b['percent'] }}%)</span>
|
||||
{{-- <span>{{ $b['label'] }} {{ $b['gb'] }} GB ({{ $b['percent'] }}%)</span>--}}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue