Files
SkinbaseNova/scripts/analyze-http-performance.php
T
klevze 8a80aae21e Ship production optimization M1-M12.5A: queues, metrics, HTTP observability, and vector search reliability.
Keep similar-ai from tripping the global circuit on a lone URL 502, clamp Qdrant search to 100, and add Server-Timing plus slow-request logging. Studio shared props, Academy S3 exists caching, heat chunking, and Redis/scheduler hygiene stay in this rollout.
2026-08-25 07:58:47 +02:00

69 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* Read-only analyzer for /var/log/nginx/skinbase-performance.log
*
* Usage:
* php scripts/analyze-http-performance.php --file=/var/log/nginx/skinbase-performance.log --since=24h --top=20 --host=skinbase.org
*/
use App\Support\Http\HttpPerformanceLogAnalyzer;
use App\Support\Http\HttpUriNormalizer;
require __DIR__.'/../vendor/autoload.php';
$options = [
'file' => '/var/log/nginx/skinbase-performance.log',
'since' => '24h',
'min_requests' => 1,
'top' => 20,
'status' => null,
'uri' => null,
'host' => null,
'slow_ms' => null,
];
foreach (array_slice($argv, 1) as $arg) {
if (! str_starts_with($arg, '--')) {
fwrite(STDERR, "Unknown argument: {$arg}\n");
exit(2);
}
[$key, $value] = array_pad(explode('=', substr($arg, 2), 2), 2, '1');
$map = [
'file' => 'file',
'since' => 'since',
'min-requests' => 'min_requests',
'top' => 'top',
'status' => 'status',
'uri' => 'uri',
'host' => 'host',
'slow-ms' => 'slow_ms',
];
if (! isset($map[$key])) {
fwrite(STDERR, "Unknown option: --{$key}\n");
exit(2);
}
$options[$map[$key]] = $value;
}
$file = (string) $options['file'];
if (! is_readable($file)) {
fwrite(STDERR, "Cannot read {$file}\n");
exit(1);
}
$analyzer = new HttpPerformanceLogAnalyzer(new HttpUriNormalizer());
$result = $analyzer->analyze($file, [
'since' => $options['since'],
'min_requests' => (int) $options['min_requests'],
'top' => (int) $options['top'],
'status' => $options['status'],
'uri' => $options['uri'],
'host' => $options['host'],
'slow_ms' => $options['slow_ms'] !== null ? (float) $options['slow_ms'] : null,
]);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;