- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
101 lines
4.1 KiB
PHP
101 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Application\Admin\System;
|
|
|
|
use App\Application\Admin\Service\AdminLayoutProcessor;
|
|
use App\Framework\Attributes\Route;
|
|
use App\Framework\Auth\Auth;
|
|
use App\Framework\Core\ValueObjects\Byte;
|
|
use App\Framework\Core\ValueObjects\Percentage;
|
|
use App\Framework\DateTime\Clock;
|
|
use App\Framework\Http\Method;
|
|
use App\Framework\Http\Request;
|
|
use App\Framework\Meta\MetaData;
|
|
use App\Framework\Performance\MemoryMonitor;
|
|
use App\Framework\Router\Result\JsonResult;
|
|
use App\Framework\Router\Result\ViewResult;
|
|
|
|
final readonly class PerformanceController
|
|
{
|
|
public function __construct(
|
|
private MemoryMonitor $memoryMonitor,
|
|
private Clock $clock,
|
|
private AdminLayoutProcessor $layoutProcessor,
|
|
) {
|
|
}
|
|
|
|
#[Auth]
|
|
#[Route(path: '/admin/system/performance', method: Method::GET, name: 'admin.system.performance')]
|
|
public function show(): ViewResult
|
|
{
|
|
/** @var array<string, mixed> $performanceData */
|
|
$performanceData = [
|
|
'currentMemoryUsage' => $this->memoryMonitor->getCurrentMemory()->toHumanReadable(),
|
|
'peakMemoryUsage' => $this->memoryMonitor->getPeakMemory()->toHumanReadable(),
|
|
'memoryLimit' => $this->memoryMonitor->getMemoryLimit()->toHumanReadable(),
|
|
'memoryUsagePercentage' => $this->memoryMonitor->getMemoryUsagePercentage()->format(2),
|
|
'loadAverage' => function_exists('sys_getloadavg') ? sys_getloadavg() : ['N/A', 'N/A', 'N/A'],
|
|
'opcacheEnabled' => function_exists('opcache_get_status') ? 'Ja' : 'Nein',
|
|
'executionTime' => number_format(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 4) . ' Sekunden',
|
|
'includedFiles' => count(get_included_files()),
|
|
'files' => get_included_files(),
|
|
];
|
|
|
|
if (function_exists('opcache_get_status')) {
|
|
try {
|
|
$opcacheStatus = opcache_get_status(false);
|
|
if ($opcacheStatus !== false) {
|
|
$memoryUsed = Byte::fromBytes($opcacheStatus['memory_usage']['used_memory']);
|
|
$performanceData['opcacheMemoryUsage'] = $memoryUsed->toHumanReadable();
|
|
$performanceData['opcacheCacheHits'] = number_format($opcacheStatus['opcache_statistics']['hits']);
|
|
|
|
$hits = $opcacheStatus['opcache_statistics']['hits'];
|
|
$misses = $opcacheStatus['opcache_statistics']['misses'];
|
|
$total = $hits + $misses;
|
|
if ($total > 0) {
|
|
$missRate = Percentage::from(($misses / $total) * 100);
|
|
$performanceData['opcacheMissRate'] = $missRate->format(2) . '%';
|
|
}
|
|
}
|
|
} catch (\Throwable $e) {
|
|
$performanceData['opcacheError'] = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'title' => 'Performance-Daten',
|
|
'performance' => $performanceData,
|
|
'current_year' => $this->clock->now()->format('Y'),
|
|
'timestamp' => $this->clock->now()->format('Y-m-d H:i:s'),
|
|
];
|
|
|
|
$finalData = $this->layoutProcessor->processLayoutFromArray($data);
|
|
|
|
return new ViewResult(
|
|
template: 'performance',
|
|
metaData: new MetaData('Performance-Daten', 'Performance-Daten'),
|
|
data: $finalData
|
|
);
|
|
}
|
|
|
|
#[Auth]
|
|
#[Route(path: '/admin/system/performance/api/realtime', method: Method::GET)]
|
|
public function getRealtimeMetrics(Request $request): JsonResult
|
|
{
|
|
$currentMemory = $this->memoryMonitor->getCurrentMemory();
|
|
$peakMemory = $this->memoryMonitor->getPeakMemory();
|
|
$usagePercentage = $this->memoryMonitor->getMemoryUsagePercentage();
|
|
|
|
return new JsonResult([
|
|
'memory' => [
|
|
'current' => $currentMemory->toHumanReadable(),
|
|
'peak' => $peakMemory->toHumanReadable(),
|
|
'usage_percentage' => round($usagePercentage->getValue(), 1),
|
|
],
|
|
'timestamp' => $this->clock->now()->format('Y-m-d H:i:s'),
|
|
]);
|
|
}
|
|
}
|