option('top')); $userId = $this->option('user') !== null ? (int) $this->option('user') : null; $statusCode = $this->option('status') !== null ? (int) $this->option('status') : null; $report = $reporter->report( from: $this->option('from') !== null ? (string) $this->option('from') : null, to: $this->option('to') !== null ? (string) $this->option('to') : null, userId: $userId, statusCode: $statusCode, top: $top, ); $this->info('API-Usage-Report'); $this->newLine(); $this->line("Requests: {$report['summary']['total_requests']}"); $this->line("Eindeutige User: {$report['summary']['unique_users']}"); $this->line("Eindeutige Tokens: {$report['summary']['unique_tokens']}"); $this->line("2xx: {$report['summary']['successful_requests']}"); $this->line("4xx: {$report['summary']['client_error_requests']}"); $this->line("5xx: {$report['summary']['server_error_requests']}"); $this->line("Durchschnitt Dauer: {$report['summary']['average_duration_ms']} ms"); $this->renderRows('Top Pfade', ['Pfad', 'Requests'], $report['top_paths']); $this->renderRows('Statuscodes', ['Status', 'Requests'], $report['status_codes']); $this->renderRows('Top User', ['User-ID', 'Requests'], $report['top_users']); $this->renderRows('Top Tokens', ['Token-ID', 'Requests'], $report['top_tokens']); if (! (bool) $this->option('no-report')) { $path = 'migration/api-usage-'.now()->format('Ymd-His').'.json'; Storage::disk('local')->put($path, json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); $this->newLine(); $this->line("Report geschrieben: storage/app/private/{$path}"); } return self::SUCCESS; } /** * @param list $headers * @param list $rows */ private function renderRows(string $title, array $headers, array $rows): void { if ($rows === []) { return; } $this->newLine(); $this->line($title); $this->table( $headers, collect($rows) ->map(fn (array $row): array => [$row['value'], $row['requests']]) ->all() ); } }