application->destination?->server; $this->serverUuid = $server?->uuid; $this->enabled = (bool) $server?->isTrafficAnalyticsEnabled(); $this->eligible = $server ? (! $server->isSwarm() && ! $server->isBuildServer()) : false; if ($this->enabled && $server) { try { $client = app(SentinelTrafficClient::class, ['server' => $server]); [$from, $to] = SentinelTrafficClient::rangeWindow('24h'); // Compose services and previews record under their own keys. Sentinel's resource // scope merges them exactly; an older Sentinel gets every key summed here. $overview = $client->tryResourceOverview($this->application->uuid, $from, $to); if ($overview === null) { $keys = $client->resourceKeys($this->application->uuid); if (count($keys) > 1) { $client->prefetchAppOverviews($keys, $from, $to); } $overviews = array_map(fn (string $key) => $client->overview($key, $from, $to), $keys); $overview = TrafficAnalyticsAggregator::sumOverviews($overviews)['overview']; } $this->overview = $overview->toArray(); } catch (\Throwable $e) { $this->overview = null; } } } public function hasData(): bool { return $this->overview !== null && (int) ($this->overview['requests'] ?? 0) > 0; } public function errorRate(): float { if (! $this->overview || (int) ($this->overview['requests'] ?? 0) === 0) { return 0.0; } $errors = (int) ($this->overview['s4xx'] ?? 0) + (int) ($this->overview['s5xx'] ?? 0); return round(($errors / $this->overview['requests']) * 100, 2); } public function placeholder(): string { return <<<'HTML'
HTML; } public function render() { return view('livewire.project.application.traffic-overview'); } }