From 5528ace09673d9c246ce9d0a1249ff9c6d6e3dd2 Mon Sep 17 00:00:00 2001 From: Christopher Horndasch Date: Sun, 29 Nov 2026 17:43:11 +0100 Subject: [PATCH] Server-Uebersicht: eigener Abschnitt "Lumina-Website" - was die Website allein belegt: Dateien nach Art (Karten-Daten, Uploads, Git-Verlauf, Bilder/Stile/Skripte, Programmcode), die Upload-Ordner im Einzelnen mit Dateizahl (Profilseiten, Symbole aus dem Spiel, Gear-Planer, Avatare ...) und die groessten Tabellen der Datenbank mit Zeilenzahl. Die Dateien misst das Sammelskript (stats_site(): ein du-Aufruf ueber das Website-Verzeichnis), die Tabellen fragt die Seite selbst ab (information_schema, server_stats_db_tables()) Co-Authored-By: Claude Fable 5.2 --- admin/server.php | 102 ++++++++++++++++++++++++++++++ includes/server_stats.php | 33 ++++++++++ includes/server_stats_collect.php | 44 +++++++++++++ 3 files changed, 179 insertions(+) diff --git a/admin/server.php b/admin/server.php index 0d21841..0676a5e 100644 --- a/admin/server.php +++ b/admin/server.php @@ -189,6 +189,108 @@ include __DIR__ . '/../includes/header.php'; + +

Lumina-Website

+

+ Nur die Website selbst – ihre Dateien' . e((string) $site['path']) . ')' : '' ?> und ihre Datenbank. + Bots, Backups und alles andere auf dem Server zählen hier nicht mit. +

+
+
+ Website gesamt + + des belegten Speichers +
+
+ Dateien + + Code, Bilder, Karten, Uploads +
+
+ Datenbank + + Tabellen +
+
+ +
Die Aufteilung der Dateien kommt mit dem nächsten Lauf des Sammelskripts (alle 15 Minuten).
+ +

Dateien der Website

+ +
+ + + + + + + + + + + + +
ArtBalkenGrößeAnteil
+
+ +

Hochgeladene Dateien nach Bereich

+ +
+ + + + + + + + + + + + +
BereichBalkenGrößeDateien
+
+ + + +

Datenbank: größte Tabellen

+ +
+ + + + + + + + + + + + + + + + + + + + +
TabelleBalkenGrößeZeilen (ca.)
Übrige Tabellen
+
+ +

Datenvolumen (Traffic)

) mit lesbarem Namen fuer die Uebersicht "Lumina-Website". */ +const SERVER_STATS_UPLOAD_LABELS = [ + 'profiles' => 'Bilder der Profilseiten', + 'avatars' => 'Profilbilder (Avatare)', + 'armory' => 'Symbole und Portraits aus dem Spiel', + 'gear' => 'Gear-Planer', + 'skills' => 'Skill-Symbole', + 'hunt' => 'Schnitzeljagd', + 'bugs' => 'Fehlermeldungen (Screenshots)', + 'maps' => 'Karten', + 'wiki' => 'Wiki', + 'roles' => 'Symbole der Gruppen', +]; + +/** + * Tabellen der Website-Datenbank nach Groesse (Daten + Indizes), groesste zuerst. Die Zeilenzahl ist bei InnoDB + * eine Schaetzung. Leer, wenn die Abfrage nicht erlaubt ist. + * + * @return array + */ +function server_stats_db_tables(): array +{ + try { + $rows = db()->query( + 'SELECT table_name AS name, COALESCE(data_length, 0) + COALESCE(index_length, 0) AS bytes, COALESCE(table_rows, 0) AS row_count + FROM information_schema.tables WHERE table_schema = DATABASE() ORDER BY bytes DESC, name' + )->fetchAll(); + } catch (PDOException $e) { + return []; + } + return array_map(static fn (array $r): array => ['name' => (string) $r['name'], 'bytes' => (int) $r['bytes'], 'rows' => (int) $r['row_count']], $rows); +} + /** Groesse lesbar: "512 MB", "63,4 GB" (1 GB = 1024 MB, wie df -h und die Angabe des Hosters). */ function format_bytes(int|float $bytes): string { diff --git a/includes/server_stats_collect.php b/includes/server_stats_collect.php index 30a170a..a675753 100644 --- a/includes/server_stats_collect.php +++ b/includes/server_stats_collect.php @@ -184,6 +184,49 @@ function stats_traffic(string $interface): array return $traffic; } +/** + * Nur die Lumina-Website: ihre Dateien nach Art und die Upload-Ordner im Einzelnen (die Datenbank fragt die Seite + * selbst ab). Ein du-Aufruf ueber das ganze Verzeichnis, daraus die einzelnen Pfade. + * + * @return array{path: string, total: int, parts: array, uploads: array} + */ +function stats_site(string $site): array +{ + $sizes = []; + foreach (explode("\n", stats_run('du -B1 --max-depth=3 ' . escapeshellarg($site))) as $line) { + if (preg_match('/^(\d+)\s+(.+)$/', $line, $m)) { + $sizes[$m[2]] = (int) $m[1]; + } + } + $total = $sizes[$site] ?? 0; + $assets = $sizes[$site . '/assets'] ?? 0; + $uploadsBytes = $sizes[$site . '/assets/uploads'] ?? 0; + $mapData = $sizes[$site . '/assets/map/data'] ?? 0; + $git = $sizes[$site . '/.git'] ?? 0; + $parts = [ + ['label' => 'Hochgeladene Dateien', 'bytes' => $uploadsBytes], + ['label' => 'Karten-Daten (Kacheln und Markierungen)', 'bytes' => $mapData], + ['label' => 'Bilder, Stile und Skripte der Website', 'bytes' => max(0, $assets - $uploadsBytes - $mapData)], + ['label' => 'Git-Verlauf', 'bytes' => $git], + ['label' => 'Programmcode', 'bytes' => max(0, $total - $assets - $git)], + ]; + usort($parts, static fn (array $a, array $b): int => $b['bytes'] <=> $a['bytes']); + + $uploads = []; + $prefix = $site . '/assets/uploads/'; + foreach ($sizes as $path => $bytes) { + if (str_starts_with($path, $prefix) && !str_contains(substr($path, strlen($prefix)), '/')) { + $uploads[] = [ + 'dir' => substr($path, strlen($prefix)), + 'bytes' => $bytes, + 'files' => (int) stats_run('find ' . escapeshellarg($path) . ' -type f | wc -l'), + ]; + } + } + usort($uploads, static fn (array $a, array $b): int => $b['bytes'] <=> $a['bytes']); + return ['path' => $site, 'total' => $total, 'parts' => $parts, 'uploads' => $uploads]; +} + $config = server_stats_config(); $target = (string) ($argv[1] ?? server_stats_file()); $site = dirname(__DIR__); @@ -249,6 +292,7 @@ $data = [ 'hostname' => (string) gethostname(), 'disk' => ['total' => $total, 'used' => $used, 'free' => $free, 'history' => $history], 'groups' => $groups, + 'site' => stats_site($site), 'tree' => stats_tree(), 'docker' => stats_docker(), 'traffic' => stats_traffic((string) ($config['interface'] ?? '')),