An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat(traffic): add bandwidth and visitor sparklines to KPI cards
Aditya Tripathi415489632bdc
diff --git a/app/Data/Traffic/TrafficSeriesBucketData.php b/app/Data/Traffic/TrafficSeriesBucketData.phpindex 077d3cf7bf..d2b7df480d 100644--- a/app/Data/Traffic/TrafficSeriesBucketData.php+++ b/app/Data/Traffic/TrafficSeriesBucketData.php@@ -13,16 +13,34 @@ class TrafficSeriesBucketData extends Datapublic int $s3xx,public int $s4xx,public int $s5xx,+ // Per-bucket aggregates (added to Sentinel's series alongside the status classes)+ // so every KPI card can draw a real sparkline. Older Sentinel omits these; they+ // default to 0 and requests falls back to the status-class sum.+ public int $requests = 0,+ public int $bytesIn = 0,+ public int $bytesOut = 0,+ public int $uniqueVisitors = 0,+ public float $p95 = 0.0,) {}public static function fromSentinel(array $row): self{+ $s2xx = (int) data_get($row, 's2xx', 0);+ $s3xx = (int) data_get($row, 's3xx', 0);+ $s4xx = (int) data_get($row, 's4xx', 0);+ $s5xx = (int) data_get($row, 's5xx', 0);+return new self(bucket: (int) data_get($row, 'bucket', 0),- s2xx: (int) data_get($row, 's2xx', 0),- s3xx: (int) data_get($row, 's3xx', 0),- s4xx: (int) data_get($row, 's4xx', 0),- s5xx: (int) data_get($row, 's5xx', 0),+ s2xx: $s2xx,+ s3xx: $s3xx,+ s4xx: $s4xx,+ s5xx: $s5xx,+ requests: (int) data_get($row, 'requests', $s2xx + $s3xx + $s4xx + $s5xx),+ bytesIn: (int) data_get($row, 'bytes_in', 0),+ bytesOut: (int) data_get($row, 'bytes_out', 0),+ uniqueVisitors: (int) data_get($row, 'unique_visitors', 0),+ p95: (float) data_get($row, 'p95', 0),);}}diff --git a/app/Livewire/Analytics.php b/app/Livewire/Analytics.phpindex faae315a4a..6c82ceb0db 100644--- a/app/Livewire/Analytics.php+++ b/app/Livewire/Analytics.php@@ -314,11 +314,17 @@ class Analytics extends Component$data = $bucket->toArray();$ts = (int) ($data['bucket'] ?? 0);- $seriesByBucket[$ts] ??= ['bucket' => $ts, 's2xx' => 0, 's3xx' => 0, 's4xx' => 0, 's5xx' => 0];+ $seriesByBucket[$ts] ??= ['bucket' => $ts, 's2xx' => 0, 's3xx' => 0, 's4xx' => 0, 's5xx' => 0, 'requests' => 0, 'bytesIn' => 0, 'bytesOut' => 0, 'uniqueVisitors' => 0, 'p95' => 0.0];$seriesByBucket[$ts]['s2xx'] += (int) ($data['s2xx'] ?? 0);$seriesByBucket[$ts]['s3xx'] += (int) ($data['s3xx'] ?? 0);$seriesByBucket[$ts]['s4xx'] += (int) ($data['s4xx'] ?? 0);$seriesByBucket[$ts]['s5xx'] += (int) ($data['s5xx'] ?? 0);+ $seriesByBucket[$ts]['requests'] += (int) ($data['requests'] ?? 0);+ $seriesByBucket[$ts]['bytesIn'] += (int) ($data['bytesIn'] ?? 0);+ $seriesByBucket[$ts]['bytesOut'] += (int) ($data['bytesOut'] ?? 0);+ // Uniques summed across servers (approximate); p95 takes the worst bucket.+ $seriesByBucket[$ts]['uniqueVisitors'] += (int) ($data['uniqueVisitors'] ?? 0);+ $seriesByBucket[$ts]['p95'] = max($seriesByBucket[$ts]['p95'], (float) ($data['p95'] ?? 0));}} catch (\Throwable $e) {// Leave this server out of the series; donut fallback covers it.@@ -405,6 +411,8 @@ class Analytics extends Component],'requestsSpark' => $this->requestsSpark(),'errorsSpark' => $this->errorsSpark(),+ 'bandwidthSpark' => $this->bandwidthSpark(),+ 'uniquesSpark' => $this->uniquesSpark(),'geo' => $this->geoMarkers(),'deviceLabels' => $device['labels'],'deviceSeries' => $device['series'],diff --git a/app/Livewire/Concerns/BuildsTrafficChartPayload.php b/app/Livewire/Concerns/BuildsTrafficChartPayload.phpindex 4d3f0809bc..40b7f6cb07 100644--- a/app/Livewire/Concerns/BuildsTrafficChartPayload.php+++ b/app/Livewire/Concerns/BuildsTrafficChartPayload.php@@ -11,7 +11,9 @@ namespace App\Livewire\Concerns;trait BuildsTrafficChartPayload{/**- * Per-bucket total requests (sum of every status class), for the Requests spark.+ * Per-bucket total requests, for the Requests spark. Derived from the status-class+ * counts (every request carries a status class), so it always matches real traffic+ * regardless of whether Sentinel populates the explicit per-bucket `requests` field.** @return array<int, int>*/@@ -36,6 +38,30 @@ trait BuildsTrafficChartPayload);}+ /**+ * Per-bucket bandwidth (bytes in + out), for the Bandwidth spark. Empty for+ * older Sentinel builds that don't emit per-bucket byte counts.+ *+ * @return array<int, int>+ */+ public function bandwidthSpark(): array+ {+ return array_map(+ fn ($b) => (int) ($b['bytesIn'] ?? 0) + (int) ($b['bytesOut'] ?? 0),+ $this->series,+ );+ }++ /**+ * Per-bucket unique visitors, for the Visitors spark.+ *+ * @return array<int, int>+ */+ public function uniquesSpark(): array+ {+ return array_map(fn ($b) => (int) ($b['uniqueVisitors'] ?? 0), $this->series);+ }+/*** Per-country marker data for the globe: [{code, requests}] over known ISO-A2 rows.*diff --git a/app/Livewire/Dashboard/TrafficAnalytics.php b/app/Livewire/Dashboard/TrafficAnalytics.phpindex f45017faec..9b1b761ed3 100644--- a/app/Livewire/Dashboard/TrafficAnalytics.php+++ b/app/Livewire/Dashboard/TrafficAnalytics.php@@ -97,11 +97,16 @@ class TrafficAnalytics extends Component$data = $bucket->toArray();$ts = (int) ($data['bucket'] ?? 0);- $seriesByBucket[$ts] ??= ['bucket' => $ts, 's2xx' => 0, 's3xx' => 0, 's4xx' => 0, 's5xx' => 0];+ $seriesByBucket[$ts] ??= ['bucket' => $ts, 's2xx' => 0, 's3xx' => 0, 's4xx' => 0, 's5xx' => 0, 'requests' => 0, 'bytesIn' => 0, 'bytesOut' => 0, 'uniqueVisitors' => 0, 'p95' => 0.0];$seriesByBucket[$ts]['s2xx'] += (int) ($data['s2xx'] ?? 0);$seriesByBucket[$ts]['s3xx'] += (int) ($data['s3xx'] ?? 0);$seriesByBucket[$ts]['s4xx'] += (int) ($data['s4xx'] ?? 0);$seriesByBucket[$ts]['s5xx'] += (int) ($data['s5xx'] ?? 0);+ $seriesByBucket[$ts]['requests'] += (int) ($data['requests'] ?? 0);+ $seriesByBucket[$ts]['bytesIn'] += (int) ($data['bytesIn'] ?? 0);+ $seriesByBucket[$ts]['bytesOut'] += (int) ($data['bytesOut'] ?? 0);+ $seriesByBucket[$ts]['uniqueVisitors'] += (int) ($data['uniqueVisitors'] ?? 0);+ $seriesByBucket[$ts]['p95'] = max($seriesByBucket[$ts]['p95'], (float) ($data['p95'] ?? 0));}} catch (\Throwable $e) {// Leave this server out of the sparkline series.@@ -134,6 +139,8 @@ class TrafficAnalytics extends Component$this->dispatch("refreshChartData-{$this->chartId}-status", ['requestsSpark' => $this->requestsSpark(),'errorsSpark' => $this->errorsSpark(),+ 'bandwidthSpark' => $this->bandwidthSpark(),+ 'uniquesSpark' => $this->uniquesSpark(),]);}diff --git a/app/Livewire/Project/Application/Analytics.php b/app/Livewire/Project/Application/Analytics.phpindex 7d2b81d7f0..6e8123a626 100644--- a/app/Livewire/Project/Application/Analytics.php+++ b/app/Livewire/Project/Application/Analytics.php@@ -152,6 +152,8 @@ class Analytics extends Component],'requestsSpark' => $this->requestsSpark(),'errorsSpark' => $this->errorsSpark(),+ 'bandwidthSpark' => $this->bandwidthSpark(),+ 'uniquesSpark' => $this->uniquesSpark(),'geo' => $this->geoMarkers(),'deviceLabels' => $device['labels'],'deviceSeries' => $device['series'],diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex 15cee733f2..d69cf61e30 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -4406,6 +4406,28 @@ function formatBytes(?int $bytes, int $precision = 2): stringreturn round($value, $precision).' '.$units[$exponent];}+/**+ * Compact human-readable count (e.g. 26_360 -> "26.36k", 1_200_000 -> "1.2M").+ * Trailing zeros are trimmed so round values read cleanly ("1k", not "1.00k").+ * Used for the dense metric columns in the traffic-analytics lists.+ */+function compactNumber(?int $n): string+{+ $n = (int) $n;++ if ($n < 1000) {+ return (string) $n;+ }++ [$divisor, $suffix] = match (true) {+ $n >= 1_000_000_000 => [1_000_000_000, 'B'],+ $n >= 1_000_000 => [1_000_000, 'M'],+ default => [1000, 'k'],+ };++ return rtrim(rtrim(number_format($n / $divisor, 2, '.', ''), '0'), '.').$suffix;+}+/*** Validates that a file path is safely within the /tmp/ directory.* Protects against unsafe parent directory paths by resolving the real pathdiff --git a/resources/css/app.css b/resources/css/app.cssindex f2ac2cbb60..cdaa8ce00b 100644--- a/resources/css/app.css+++ b/resources/css/app.css@@ -81,6 +81,9 @@--chart-status-4xx: #d97706;--chart-status-5xx: #dc2626;+ /* KPI sparkline accent for Bandwidth (violet — distinct from the status hues). */+ --chart-spark-bandwidth: #7c3aed;+/* Sequential 5-step geo ramp (low -> high traffic) + neutral empty. */--chart-geo-1: #3b82f6;--chart-geo-2: #2563eb;@@ -97,6 +100,8 @@--chart-status-4xx: #f59e0b;--chart-status-5xx: #ef4444;+ --chart-spark-bandwidth: #a78bfa;+--chart-geo-1: #2563eb;--chart-geo-2: #3b82f6;--chart-geo-3: #60a5fa;diff --git a/resources/js/traffic-globe.js b/resources/js/traffic-globe.jsindex ef8ac90645..49f52ac9ac 100644--- a/resources/js/traffic-globe.js+++ b/resources/js/traffic-globe.js@@ -9,17 +9,17 @@ const CENTROIDS = {"AD":[42.546245,1.601554],"AE":[23.424076,53.847818],"AF":[33const THEMES = {dark: {dark: 1,- baseColor: [0.28, 0.32, 0.4],- markerColor: [0.36, 0.55, 1],- glowColor: [0.06, 0.09, 0.16],- mapBrightness: 5,+ baseColor: [0.45, 0.5, 0.62],+ markerColor: [0.36, 0.6, 1],+ glowColor: [0.12, 0.16, 0.26],+ mapBrightness: 11,},light: {dark: 0,- baseColor: [0.86, 0.88, 0.92],- markerColor: [0.15, 0.39, 0.92],+ baseColor: [0.82, 0.85, 0.9],+ markerColor: [0.13, 0.36, 0.92],glowColor: [1, 1, 1],- mapBrightness: 8,+ mapBrightness: 9,},};@@ -47,10 +47,31 @@ function buildMarkers(data) {}));}+const TWO_PI = Math.PI * 2;++// cobe orientation for a lat/lng so the point faces the viewer (cobe's own+// focus example formula). Returns [phi, theta].+function locationToAngles(lat, lng) {+ return [Math.PI - ((lng * Math.PI) / 180 - Math.PI / 2), (lat * Math.PI) / 180];+}++// Shortest-path angular interpolation, so easing across the 0/2π seam never+// spins the long way around.+function lerpAngle(current, target, t) {+ let delta = ((target - current + Math.PI) % TWO_PI + TWO_PI) % TWO_PI - Math.PI;++ return current + delta * t;+}+/*** Mount an interactive, drag-to-rotate dotted globe onto a canvas. Returns a- * controller with `update(data, dark)` to swap markers/theme and `destroy()`.- * The globe auto-rotates until the pointer grabs it, then resumes on release.+ * controller with `update(data, dark)`, `focus(code)`, `resume()` and+ * `destroy()`. The globe auto-rotates, pauses while grabbed or while a country+ * is hover-focused, and eases smoothly toward whatever it's pointed at.+ *+ * cobe v2 has no internal render loop or `onRender` callback: createGlobe draws+ * a single frame and returns `{ update, destroy }`. We drive our own rAF loop,+ * calling `globe.update({...})` each frame for rotation and to swap markers/theme.** @param {HTMLCanvasElement} canvas* @param {Array<{code: string, requests: number}>} data@@ -59,32 +80,41 @@ function buildMarkers(data) {function mountTrafficGlobe(canvas, data, dark) {let globe = null;let width = 0;- let phi = 0;- let theta = 0.25;- let pointerInteracting = null;- let pointerMovement = 0;let destroyed = false;+ let rafId = 0;+ let markers = buildMarkers(data);- const onResize = () => {- width = canvas.offsetWidth;- };- onResize();- const resizeObserver = new ResizeObserver(onResize);- resizeObserver.observe(canvas);+ // Ambient spin is decorative; honor reduced-motion by not auto-rotating+ // (drag + hover-focus still work — those are user-initiated).+ const prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;++ // Rotation is a single moving target the loop eases toward each frame.+ let targetPhi = 0;+ let currentPhi = 0;+ let targetTheta = 0.2;+ let currentTheta = 0.2;+ let autoRotate = !prefersReduced;++ let dragging = null; // clientX at pointerdown+ let dragStartPhi = 0;const onPointerDown = (e) => {- pointerInteracting = e.clientX - pointerMovement;+ dragging = e.clientX;+ dragStartPhi = targetPhi;+ autoRotate = false;canvas.style.cursor = 'grabbing';};const onPointerUp = () => {- pointerInteracting = null;+ if (dragging === null) {+ return;+ }+ dragging = null;+ autoRotate = ! prefersReduced;canvas.style.cursor = 'grab';};const onPointerMove = (e) => {- if (pointerInteracting !== null) {- const delta = e.clientX - pointerInteracting;- pointerMovement = delta;- phi = delta / 200;+ if (dragging !== null) {+ targetPhi = dragStartPhi + (e.clientX - dragging) / 150;}};@@ -93,16 +123,15 @@ function mountTrafficGlobe(canvas, data, dark) {window.addEventListener('pointermove', onPointerMove);canvas.style.cursor = 'grab';- const create = (rows, isDark) => {+ const create = (isDark) => {const theme = isDark ? THEMES.dark : THEMES.light;- let autoRotate = 0;globe = createGlobe(canvas, {devicePixelRatio: 2,- width: width * 2,- height: width * 2,- phi: 0,- theta,+ width: width,+ height: width,+ phi: currentPhi,+ theta: currentTheta,diffuse: 1.2,mapSamples: 16000,mapBrightness: theme.mapBrightness,@@ -110,34 +139,91 @@ function mountTrafficGlobe(canvas, data, dark) {baseColor: theme.baseColor,markerColor: theme.markerColor,glowColor: theme.glowColor,- opacity: 0.9,- markers: buildMarkers(rows),- onRender: (state) => {- if (pointerInteracting === null) {- autoRotate += 0.0025;- }- state.phi = autoRotate + phi;- state.width = width * 2;- state.height = width * 2;- },+ opacity: 0.92,+ markers: markers,});};- create(data, dark);+ // Self-driven animation loop (cobe v2 draws only when we call update()).+ const tick = () => {+ if (destroyed) {+ return;+ }+ if (globe && width > 0) {+ if (autoRotate && dragging === null) {+ targetPhi += 0.0025;+ }+ currentPhi = lerpAngle(currentPhi, targetPhi, 0.12);+ currentTheta += (targetTheta - currentTheta) * 0.12;+ globe.update({ phi: currentPhi, theta: currentTheta, width: width, height: width, markers });+ }+ rafId = requestAnimationFrame(tick);+ };++ // cobe needs a non-zero canvas width at creation; inside a freshly-rendered+ // or momentarily-hidden container offsetWidth can be 0, which yields a blank+ // globe (only the grab cursor shows). Create once a real width is known.+ const ensure = () => {+ const next = canvas.offsetWidth;+ if (destroyed || next === 0 || globe) {+ return;+ }+ width = next;+ create(dark);+ rafId = requestAnimationFrame(tick);+ };++ const resizeObserver = new ResizeObserver(() => {+ if (globe) {+ width = canvas.offsetWidth || width;+ } else {+ ensure();+ }+ });+ resizeObserver.observe(canvas);+ requestAnimationFrame(ensure);return {update(newData, isDark) {if (destroyed) {return;}- // cobe fixes markers at creation, so swap by recreating in place.+ data = newData;+ dark = isDark;+ markers = buildMarkers(newData);if (globe) {- globe.destroy();+ const theme = isDark ? THEMES.dark : THEMES.light;+ globe.update({+ markers,+ dark: theme.dark,+ mapBrightness: theme.mapBrightness,+ baseColor: theme.baseColor,+ markerColor: theme.markerColor,+ glowColor: theme.glowColor,+ });+ }+ },+ focus(code) {+ const c = CENTROIDS[String(code || '').toUpperCase()];+ if (!c) {+ return;+ }+ const [phi, theta] = locationToAngles(c[0], c[1]);+ targetPhi = phi;+ targetTheta = theta;+ autoRotate = false;+ },+ resume() {+ if (dragging === null) {+ autoRotate = ! prefersReduced;}- create(newData, isDark);},destroy() {destroyed = true;+ if (rafId) {+ cancelAnimationFrame(rafId);+ rafId = 0;+ }resizeObserver.disconnect();canvas.removeEventListener('pointerdown', onPointerDown);window.removeEventListener('pointerup', onPointerUp);diff --git a/resources/views/livewire/analytics.blade.php b/resources/views/livewire/analytics.blade.phpindex f8ed17656d..19c1524642 100644--- a/resources/views/livewire/analytics.blade.php+++ b/resources/views/livewire/analytics.blade.php@@ -128,49 +128,72 @@ $appListboxOptions = array_merge(<x-application.settings-section id="analytics-overview-section" title="Overview"helper="Aggregate request volume for the selected filters and range."><div class="grid grid-cols-2 gap-px overflow-hidden rounded-lg bg-neutral-200 sm:grid-cols-3 lg:grid-cols-5 dark:bg-white/[0.07]">- <div class="flex flex-col gap-2 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Requests</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['requests'] ?? 0) }}</span>- @include('livewire.traffic._sparkline', [- 'id' => $chartId.'-spark-requests',- 'initial' => $this->requestsSpark(),- 'colorVar' => '--chart-status-3xx',- 'event' => 'refreshChartData-'.$chartId.'-status',- 'key' => 'requestsSpark',- ])+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['requests'] ?? 0) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-requests',+ 'initial' => $this->requestsSpark(),+ 'colorVar' => '--chart-status-3xx',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'requestsSpark',+ ])+ </div></div>- <div class="flex flex-col gap-1 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="flex items-center text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Unique visitors@if ($uniquesApproximate){!! $approxBadge('Summed across servers; visitors seen on multiple servers may be double-counted.') !!}@endif</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['uniqueVisitors'] ?? 0) }}</span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['uniqueVisitors'] ?? 0) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-visitors',+ 'initial' => $this->uniquesSpark(),+ 'colorVar' => '--chart-status-2xx',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'uniquesSpark',+ ])+ </div></div>- <div class="flex flex-col gap-1 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Bandwidth</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ formatBytes($this->bandwidthBytes()) }}</span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ formatBytes($this->bandwidthBytes()) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-bandwidth',+ 'initial' => $this->bandwidthSpark(),+ 'colorVar' => '--chart-spark-bandwidth',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'bandwidthSpark',+ ])+ </div></div>- <div class="flex flex-col gap-2 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Error rate</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ $this->errorRate() }}%</span>- @include('livewire.traffic._sparkline', [- 'id' => $chartId.'-spark-errors',- 'initial' => $this->errorsSpark(),- 'colorVar' => '--chart-status-5xx',- 'event' => 'refreshChartData-'.$chartId.'-status',- 'key' => 'errorsSpark',- ])+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ $this->errorRate() }}%</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-errors',+ 'initial' => $this->errorsSpark(),+ 'colorVar' => '--chart-status-5xx',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'errorsSpark',+ ])+ </div></div>- <div class="flex flex-col gap-1 bg-white px-4 py-3 dark:bg-base">+ <div class="col-span-2 flex flex-col bg-white px-4 py-3 sm:col-span-1 dark:bg-base"><span class="flex items-center text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">p95 latency@if ($latencyApproximate){!! $approxBadge('Highest p95 latency across servers; not a true cross-server percentile.') !!}@endif</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['latencyP95'] ?? 0, 1) }} ms</span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['latencyP95'] ?? 0, 1) }} ms</span>+ <div class="mt-auto pt-3"><div class="h-9"></div></div></div></div></x-application.settings-section>@@ -197,9 +220,13 @@ $appListboxOptions = array_merge(description="No per-application requests were recorded for the selected range."icon-name="unordered-list" />@else+ @php $maxAppRequests = max(1, (int) collect($topApps)->max('requests')); @endphp<div x-data="{ page: 0, per: 10, total: {{ count($topApps) }} }">@foreach ($topApps as $row)- @php $appHref = $row['link'] ?? null; @endphp+ @php+ $appHref = $row['link'] ?? null;+ $appWidth = min(100, round(($row['requests'] / $maxAppRequests) * 100, 1));+ @endphp<{{ $appHref ? 'a' : 'div' }} wire:key="analytics-app-{{ $row['uuid'] }}"@if ($appHref) href="{{ $appHref }}" {{ wireNavigate() }} @endifx-show="{{ $loop->index }} >= page * per && {{ $loop->index }} < (page + 1) * per"@@ -213,8 +240,12 @@ $appListboxOptions = array_merge(<span class="hidden truncate text-[11px] text-neutral-400 sm:inline dark:text-fg-faint">{{ $row['domain'] }}</span>@endif</span>- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ number_format($row['requests']) }} req</span>- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ formatBytes($row['bandwidth']) }}</span>+ <div class="hidden h-1 w-16 shrink-0 overflow-hidden rounded-full bg-neutral-100 sm:block dark:bg-white/[0.06]">+ <div class="h-full rounded-full bg-[var(--chart-status-3xx)]" style="width: {{ $appWidth }}%;"></div>+ </div>+ <span class="w-12 shrink-0 text-right text-[12px] font-medium tabular-nums text-black dark:text-fg"+ title="{{ number_format($row['requests']) }} requests">{{ compactNumber($row['requests']) }}</span>+ <span class="hidden w-16 shrink-0 text-right text-[11px] tabular-nums text-neutral-400 sm:inline dark:text-fg-faint">{{ formatBytes($row['bandwidth']) }}</span>@if ($appHref)<svg class="size-3.5 shrink-0 text-neutral-300 dark:text-fg-faint" viewBox="0 0 24 24"fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">diff --git a/resources/views/livewire/dashboard/traffic-analytics.blade.php b/resources/views/livewire/dashboard/traffic-analytics.blade.phpindex 66f139f07d..dcffccb020 100644--- a/resources/views/livewire/dashboard/traffic-analytics.blade.php+++ b/resources/views/livewire/dashboard/traffic-analytics.blade.php@@ -96,45 +96,65 @@ $spark = 'refreshChartData-'.$chartId.'-status';{{-- Sparkline KPI cards. Each links through to the full analytics page. --}}<div class="grid grid-cols-1 gap-px overflow-hidden rounded-xl bg-neutral-200 sm:grid-cols-2 lg:grid-cols-4 dark:bg-white/[0.07]"><a href="{{ route('analytics') }}" {{ wireNavigate() }}- class="group flex flex-col gap-2 bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]">+ class="group flex flex-col bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Requests</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['requests'] ?? 0) }}</span>- @include('livewire.traffic._sparkline', [- 'id' => $chartId.'-spark-requests',- 'initial' => $this->requestsSpark(),- 'colorVar' => '--chart-status-3xx',- 'event' => $spark,- 'key' => 'requestsSpark',- ])+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['requests'] ?? 0) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-requests',+ 'initial' => $this->requestsSpark(),+ 'colorVar' => '--chart-status-3xx',+ 'event' => $spark,+ 'key' => 'requestsSpark',+ ])+ </div></a><a href="{{ route('analytics') }}" {{ wireNavigate() }}- class="group flex flex-col gap-2 bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]">+ class="group flex flex-col bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]"><span class="flex items-center text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Unique visitors@if ($uniquesApproximate){!! $approxBadge('Summed across '.$servers->count().' servers; visitors seen on multiple servers may be double-counted.') !!}@endif</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['uniqueVisitors'] ?? 0) }}</span>- <span class="mt-auto h-9"></span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['uniqueVisitors'] ?? 0) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-visitors',+ 'initial' => $this->uniquesSpark(),+ 'colorVar' => '--chart-status-2xx',+ 'event' => $spark,+ 'key' => 'uniquesSpark',+ ])+ </div></a><a href="{{ route('analytics') }}" {{ wireNavigate() }}- class="group flex flex-col gap-2 bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]">+ class="group flex flex-col bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Bandwidth</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ formatBytes($this->bandwidthBytes()) }}</span>- <span class="mt-auto h-9"></span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ formatBytes($this->bandwidthBytes()) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-bandwidth',+ 'initial' => $this->bandwidthSpark(),+ 'colorVar' => '--chart-spark-bandwidth',+ 'event' => $spark,+ 'key' => 'bandwidthSpark',+ ])+ </div></a><a href="{{ route('analytics') }}" {{ wireNavigate() }}- class="group flex flex-col gap-2 bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]">+ class="group flex flex-col bg-white px-4 py-3 transition-colors hover:bg-neutral-50 dark:bg-base dark:hover:bg-white/[0.03]"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Error rate</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ $this->errorRate() }}%</span>- @include('livewire.traffic._sparkline', [- 'id' => $chartId.'-spark-errors',- 'initial' => $this->errorsSpark(),- 'colorVar' => '--chart-status-5xx',- 'event' => $spark,- 'key' => 'errorsSpark',- ])+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ $this->errorRate() }}%</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-errors',+ 'initial' => $this->errorsSpark(),+ 'colorVar' => '--chart-status-5xx',+ 'event' => $spark,+ 'key' => 'errorsSpark',+ ])+ </div></a></div>@endifdiff --git a/resources/views/livewire/project/application/analytics.blade.php b/resources/views/livewire/project/application/analytics.blade.phpindex 43799934f9..e7cdda83db 100644--- a/resources/views/livewire/project/application/analytics.blade.php+++ b/resources/views/livewire/project/application/analytics.blade.php@@ -62,39 +62,62 @@ $analyticsServerUuid = $application->destination?->server?->uuid;</x-slot:actions><div class="grid grid-cols-2 gap-px overflow-hidden rounded-lg bg-neutral-200 sm:grid-cols-3 lg:grid-cols-5 dark:bg-white/[0.07]">- <div class="flex flex-col gap-2 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Requests</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['requests'] ?? 0) }}</span>- @include('livewire.traffic._sparkline', [- 'id' => $chartId.'-spark-requests',- 'initial' => $this->requestsSpark(),- 'colorVar' => '--chart-status-3xx',- 'event' => 'refreshChartData-'.$chartId.'-status',- 'key' => 'requestsSpark',- ])+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['requests'] ?? 0) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-requests',+ 'initial' => $this->requestsSpark(),+ 'colorVar' => '--chart-status-3xx',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'requestsSpark',+ ])+ </div></div>- <div class="flex flex-col gap-1 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Unique visitors</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['uniqueVisitors'] ?? 0) }}</span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['uniqueVisitors'] ?? 0) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-visitors',+ 'initial' => $this->uniquesSpark(),+ 'colorVar' => '--chart-status-2xx',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'uniquesSpark',+ ])+ </div></div>- <div class="flex flex-col gap-1 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Bandwidth</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ formatBytes($this->bandwidthBytes()) }}</span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ formatBytes($this->bandwidthBytes()) }}</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-bandwidth',+ 'initial' => $this->bandwidthSpark(),+ 'colorVar' => '--chart-spark-bandwidth',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'bandwidthSpark',+ ])+ </div></div>- <div class="flex flex-col gap-2 bg-white px-4 py-3 dark:bg-base">+ <div class="flex flex-col bg-white px-4 py-3 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">Error rate</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ $this->errorRate() }}%</span>- @include('livewire.traffic._sparkline', [- 'id' => $chartId.'-spark-errors',- 'initial' => $this->errorsSpark(),- 'colorVar' => '--chart-status-5xx',- 'event' => 'refreshChartData-'.$chartId.'-status',- 'key' => 'errorsSpark',- ])+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ $this->errorRate() }}%</span>+ <div class="mt-auto pt-3">+ @include('livewire.traffic._sparkline', [+ 'id' => $chartId.'-spark-errors',+ 'initial' => $this->errorsSpark(),+ 'colorVar' => '--chart-status-5xx',+ 'event' => 'refreshChartData-'.$chartId.'-status',+ 'key' => 'errorsSpark',+ ])+ </div></div>- <div class="flex flex-col gap-1 bg-white px-4 py-3 dark:bg-base">+ <div class="col-span-2 flex flex-col bg-white px-4 py-3 sm:col-span-1 dark:bg-base"><span class="text-[11px] font-medium tracking-wide text-neutral-500 uppercase dark:text-fg-dim">p95 latency</span>- <span class="text-xl font-semibold text-black dark:text-fg">{{ number_format($overview['latencyP95'] ?? 0, 1) }} ms</span>+ <span class="mt-1 text-xl font-semibold text-black tabular-nums dark:text-fg">{{ number_format($overview['latencyP95'] ?? 0, 1) }} ms</span>+ <div class="mt-auto pt-3"><div class="h-9"></div></div></div></div></x-application.settings-section>diff --git a/resources/views/livewire/traffic/_breakdown-section.blade.php b/resources/views/livewire/traffic/_breakdown-section.blade.phpindex e3d56bc453..c955350ba3 100644--- a/resources/views/livewire/traffic/_breakdown-section.blade.php+++ b/resources/views/livewire/traffic/_breakdown-section.blade.php@@ -13,6 +13,7 @@@php$rows = $rows ?? [];$helper = $helper ?? 'Top '.strtolower($label).' by request count for the selected range.';+ $maxRequests = max(1, (int) collect($rows)->max('requests'));@endphp<x-application.settings-section id="analytics-{{ $dimension }}-section" :title="$label" :helper="$helper" flush>@if (empty($rows))@@ -32,6 +33,8 @@'referer' => $host ?? 'Direct / none',default => $value !== '' ? $value : 'Unknown',};+ $requests = (int) ($row['requests'] ?? 0);+ $width = min(100, round(($requests / $maxRequests) * 100, 1));@endphp<div wire:key="analytics-{{ $dimension }}-{{ $loop->index }}"x-show="{{ $loop->index }} >= page * per && {{ $loop->index }} < (page + 1) * per"@@ -44,8 +47,12 @@@else<span class="min-w-0 flex-1 truncate text-[12px] text-black dark:text-fg" title="{{ $display }}">{{ $display }}</span>@endif- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ number_format((int) ($row['requests'] ?? 0)) }} req</span>- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ formatBytes((int) ($row['bytesOut'] ?? 0)) }}</span>+ <div class="hidden h-1 w-16 shrink-0 overflow-hidden rounded-full bg-neutral-100 sm:block dark:bg-white/[0.06]">+ <div class="h-full rounded-full bg-[var(--chart-status-3xx)]" style="width: {{ $width }}%;"></div>+ </div>+ <span class="w-12 shrink-0 text-right text-[12px] font-medium tabular-nums text-black dark:text-fg"+ title="{{ number_format($requests) }} requests">{{ compactNumber($requests) }}</span>+ <span class="hidden w-16 shrink-0 text-right text-[11px] tabular-nums text-neutral-400 sm:inline dark:text-fg-faint">{{ formatBytes((int) ($row['bytesOut'] ?? 0)) }}</span></div>@endforeach@include('livewire.traffic._pager')diff --git a/resources/views/livewire/traffic/_geo.blade.php b/resources/views/livewire/traffic/_geo.blade.phpindex ae1976db5d..f47e0506bf 100644--- a/resources/views/livewire/traffic/_geo.blade.php+++ b/resources/views/livewire/traffic/_geo.blade.php@@ -1,11 +1,11 @@{{--Shared geo visualization for traffic analytics: a lightweight interactive 3Ddotted globe (WebGL, via cobe — see resources/js/traffic-globe.js) with a- request-volume marker per country, plus a ranked, paginated country list.- Driven by the `country` breakdown; each row is ['value' => ISO-A2, 'requests',- 'bytesOut']. The globe live-updates from the host's- `refreshChartData-{chartId}-status` payload (`geo` key), so `$chartId` must be- in scope. Bars/flags in the list reuse the --chart-geo-* tokens.+ request-volume marker per country, beside a scrollable ranked country list.+ Hovering a country row rotates the globe to face it. Driven by the `country`+ breakdown; each row is ['value' => ISO-A2, 'requests', 'bytesOut']. The globe+ live-updates from the host's `refreshChartData-{chartId}-status` payload+ (`geo` key), so `$chartId` must be in scope.@param iterable $countries country-breakdown rows@param ?string $attribution optional Sentinel attribution note@@ -25,15 +25,6 @@fn ($r) => preg_match('/^[A-Z]{2}$/', $r['value']) && countryName($r['value']) !== 'Unknown');- // Quantile buckets (1..5) over known countries for the list bars.- $knownSorted = $known->sortBy('requests')->values();- $bucketCount = $knownSorted->count();- $bucketMap = [];- foreach ($knownSorted as $i => $r) {- $bucket = $bucketCount <= 1 ? 5 : (int) floor(($i / $bucketCount) * 5) + 1;- $bucketMap[$r['value']] = min(5, max(1, $bucket));- }-// Initial marker payload for the globe, keyed by ISO-A2 request volume.$geoInit = $known->map(fn ($r) => ['code' => $r['value'], 'requests' => $r['requests']])->values()->all();@@ -57,47 +48,58 @@<x-empty size="sm" title="No data" description="No country data for the selected range."icon-name="network" />@else- <div class="grid grid-cols-1 gap-4 border-b border-neutral-200 p-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.1fr)] dark:border-white/[0.07]">- {{-- Interactive dotted globe. wire:ignore so live-poll morphs never tear down the WebGL canvas. --}}- <div wire:ignore class="relative mx-auto flex aspect-square w-full max-w-[360px] items-center justify-center">- <canvas id="{!! $globeId !!}"- class="h-full w-full [contain:layout_paint_size] [touch-action:none]"- style="width: 100%; height: 100%;"></canvas>+ <div class="grid grid-cols-1 items-stretch gap-4 border-b border-neutral-200 p-4 lg:grid-cols-[2fr_3fr] dark:border-white/[0.07]">+ {{-- Interactive dotted globe (40%). wire:ignore so live-poll morphs never tear+ down the WebGL canvas. --}}+ <div wire:ignore class="flex items-center justify-center">+ <div class="relative aspect-square w-full max-w-[320px]">+ <canvas id="{!! $globeId !!}"+ class="h-full w-full [touch-action:none]"+ style="width: 100%; height: 100%;"></canvas>+ </div></div>- {{-- Ranked country list (updates via morph on range/live refresh). --}}- <div class="min-w-0 self-center" x-data="{ page: 0, per: 10, total: {{ $countryRows->count() }} }">- @foreach ($countryRows as $row)- @php- $isUnknown = $row['value'] === '';- $bucket = $isUnknown ? null : ($bucketMap[$row['value']] ?? 1);- $width = min(100, round(($row['requests'] / $maxRequests) * 100, 1));- $barColor = $isUnknown ? 'var(--chart-geo-empty)' : "var(--chart-geo-{$bucket})";- @endphp- <div wire:key="geo-country-{{ $globeId }}-{{ $loop->index }}"- x-show="{{ $loop->index }} >= page * per && {{ $loop->index }} < (page + 1) * per"- class="flex min-h-11 items-center gap-3 border-b border-neutral-200 py-2 last:border-b-0 dark:border-white/[0.07]">- @php $flagUrl = $isUnknown ? null : countryFlagUrl($row['value']); @endphp- @if ($flagUrl)- <img src="{{ $flagUrl }}" srcset="{{ countryFlagUrl($row['value'], '48x36') }} 2x" alt=""- loading="lazy" width="20" height="15"- class="h-[15px] w-5 shrink-0 rounded-[2px] object-cover ring-1 ring-black/5 dark:ring-white/10"- onerror="this.style.visibility='hidden'">- @else- <span class="shrink-0 text-[14px] leading-none" aria-hidden="true">🌐</span>- @endif- <span class="min-w-0 flex-1 truncate text-[12px] text-black dark:text-fg">- {{ $isUnknown ? 'Unknown' : countryName($row['value']) }}- </span>- <div class="hidden h-1.5 w-24 shrink-0 overflow-hidden rounded-full bg-neutral-100 sm:block dark:bg-white/[0.06]">- <div class="h-full rounded-full" style="width: {{ $width }}%; background-color: {{ $barColor }};"></div>+ {{-- Ranked, scrollable country list (60%). Hover a row to face it on the globe. --}}+ <div class="min-w-0" x-data="{+ focus(code) {+ const g = document.getElementById('{!! $globeId !!}');+ if (g && g._trafficGlobe) { g._trafficGlobe.focus(code); }+ },+ blur() {+ const g = document.getElementById('{!! $globeId !!}');+ if (g && g._trafficGlobe) { g._trafficGlobe.resume(); }+ },+ }">+ <div class="max-h-[320px] overflow-y-auto pr-1 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-neutral-300 dark:scrollbar-thumb-white/10">+ @foreach ($countryRows as $row)+ @php+ $isUnknown = $row['value'] === '';+ $width = min(100, round(($row['requests'] / $maxRequests) * 100, 1));+ @endphp+ <div wire:key="geo-country-{{ $globeId }}-{{ $loop->index }}"+ @if (! $isUnknown) @mouseenter="focus('{{ $row['value'] }}')" @mouseleave="blur()" @endif+ class="group flex min-h-10 items-center gap-3 rounded-md px-2 py-1.5 transition-colors hover:bg-neutral-50 dark:hover:bg-white/[0.03]">+ @php $flagUrl = $isUnknown ? null : countryFlagUrl($row['value']); @endphp+ @if ($flagUrl)+ <img src="{{ $flagUrl }}" srcset="{{ countryFlagUrl($row['value'], '48x36') }} 2x" alt=""+ loading="lazy" width="20" height="15"+ class="h-[15px] w-5 shrink-0 rounded-[2px] object-cover ring-1 ring-black/5 dark:ring-white/10"+ onerror="this.style.visibility='hidden'">+ @else+ <span class="shrink-0 text-[14px] leading-none" aria-hidden="true">🌐</span>+ @endif+ <span class="min-w-0 flex-1 truncate text-[12px] text-black dark:text-fg">+ {{ $isUnknown ? 'Unknown' : countryName($row['value']) }}+ </span>+ <div class="hidden h-1 w-16 shrink-0 overflow-hidden rounded-full bg-neutral-100 sm:block dark:bg-white/[0.06]">+ <div class="h-full rounded-full bg-[var(--chart-status-3xx)]" style="width: {{ $width }}%;"></div>+ </div>+ <span class="w-12 shrink-0 text-right text-[12px] font-medium tabular-nums text-black dark:text-fg"+ title="{{ number_format($row['requests']) }} requests">{{ compactNumber($row['requests']) }}</span>+ <span class="hidden w-16 shrink-0 text-right text-[11px] tabular-nums text-neutral-400 sm:inline dark:text-fg-faint">{{ formatBytes($row['bytesOut']) }}</span></div>- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ number_format($row['requests']) }} req</span>- <span class="hidden shrink-0 text-[12px] text-neutral-500 sm:inline dark:text-fg-dim">{{ formatBytes($row['bytesOut']) }}</span>- </div>- @endforeach-- @include('livewire.traffic._pager')+ @endforeach+ </div></div></div>@@ -114,7 +116,9 @@if (!canvas || typeof window.mountTrafficGlobe !== 'function') { return; }const isDark = () => document.documentElement.classList.contains('dark');- let controller = window.mountTrafficGlobe(canvas, @json($geoInit), isDark());+ const controller = window.mountTrafficGlobe(canvas, @json($geoInit), isDark());+ // Expose for row-hover focus() from the Alpine list scope.+ canvas._trafficGlobe = controller;Livewire.on('refreshChartData-{!! $chartId !!}-status', payload => {const data = Array.isArray(payload) ? payload[0] : payload;@@ -125,7 +129,7 @@// Tear down the WebGL context when navigating away (wire:navigate).document.addEventListener('livewire:navigating', () => {- if (controller) { controller.destroy(); controller = null; }+ if (canvas._trafficGlobe) { canvas._trafficGlobe.destroy(); canvas._trafficGlobe = null; }}, { once: true });})();</script>diff --git a/resources/views/livewire/traffic/_hosts-list.blade.php b/resources/views/livewire/traffic/_hosts-list.blade.phpindex 56352e0f08..0a1eda3a34 100644--- a/resources/views/livewire/traffic/_hosts-list.blade.php+++ b/resources/views/livewire/traffic/_hosts-list.blade.php@@ -1,7 +1,7 @@{{--Paginated "top hosts" list — request volume grouped by served hostname (an app's- primary domain). Mirrors the top-paths presentation; links each host to its live- origin. Expects `$hosts` in scope.+ primary domain), with a proportional bar and right-aligned compact metrics.+ Links each host to its live origin. Expects `$hosts` in scope.@param iterable $hosts host rows: ['host', 'requests', 'bandwidth']@param ?string $keyPrefix wire:key prefix (default "analytics-host")@@ -9,6 +9,7 @@@php$hosts = $hosts ?? [];$keyPrefix = $keyPrefix ?? 'analytics-host';+ $maxRequests = max(1, (int) collect($hosts)->max('requests'));@endphp@if (empty($hosts))<x-empty size="sm" title="No host data" description="No hostnames were recorded for the selected range."@@ -19,6 +20,8 @@@php$host = (string) ($row['host'] ?? '');$known = $host !== '';+ $requests = (int) ($row['requests'] ?? 0);+ $width = min(100, round(($requests / $maxRequests) * 100, 1));@endphp<div wire:key="{{ $keyPrefix }}-{{ $loop->index }}"x-show="{{ $loop->index }} >= page * per && {{ $loop->index }} < (page + 1) * per"@@ -29,8 +32,12 @@@else<span class="min-w-0 flex-1 truncate text-[12px] text-neutral-500 dark:text-fg-dim">Unknown host</span>@endif- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ number_format((int) ($row['requests'] ?? 0)) }} req</span>- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ formatBytes((int) ($row['bandwidth'] ?? 0)) }}</span>+ <div class="hidden h-1 w-16 shrink-0 overflow-hidden rounded-full bg-neutral-100 sm:block dark:bg-white/[0.06]">+ <div class="h-full rounded-full bg-[var(--chart-status-3xx)]" style="width: {{ $width }}%;"></div>+ </div>+ <span class="w-12 shrink-0 text-right text-[12px] font-medium tabular-nums text-black dark:text-fg"+ title="{{ number_format($requests) }} requests">{{ compactNumber($requests) }}</span>+ <span class="hidden w-16 shrink-0 text-right text-[11px] tabular-nums text-neutral-400 sm:inline dark:text-fg-faint">{{ formatBytes((int) ($row['bandwidth'] ?? 0)) }}</span></div>@endforeach@include('livewire.traffic._pager')diff --git a/resources/views/livewire/traffic/_paths-list.blade.php b/resources/views/livewire/traffic/_paths-list.blade.phpindex 483b5ff832..c889e363e0 100644--- a/resources/views/livewire/traffic/_paths-list.blade.php+++ b/resources/views/livewire/traffic/_paths-list.blade.php@@ -1,7 +1,9 @@{{--- Paginated "top paths" list. Each row shows the request path and links it to its- live URL when the owning domain is known (new tab, rel="noopener noreferrer- nofollow"). Expects `$paths` in scope; optional `$keyPrefix` to namespace wire:keys.+ Paginated "top paths" list. Each row shows the request path, a proportional+ request-volume bar, and right-aligned compact metrics (requests / bytes / p95).+ The path links to its live URL when the owning domain is known (new tab,+ rel="noopener noreferrer nofollow"). Expects `$paths` in scope; optional+ `$keyPrefix` to namespace wire:keys.@param iterable $paths path rows: ['path', 'domain'?, 'requests', 'bytesOut', 'p95']@param ?string $keyPrefix wire:key prefix (default "analytics-path")@@ -9,6 +11,7 @@@php$paths = $paths ?? [];$keyPrefix = $keyPrefix ?? 'analytics-path';+ $maxRequests = max(1, (int) collect($paths)->max('requests'));@endphp@if (empty($paths))<x-empty size="sm" title="No path data" description="No requests were recorded for the selected range."@@ -20,6 +23,8 @@$domain = $path['domain'] ?? null;$pathStr = (string) ($path['path'] ?? '');$href = $domain ? 'https://'.$domain.$pathStr : null;+ $requests = (int) ($path['requests'] ?? 0);+ $width = min(100, round(($requests / $maxRequests) * 100, 1));@endphp<div wire:key="{{ $keyPrefix }}-{{ $loop->index }}"x-show="{{ $loop->index }} >= page * per && {{ $loop->index }} < (page + 1) * per"@@ -30,9 +35,14 @@@else<span class="min-w-0 flex-1 truncate font-mono text-[12px] text-black dark:text-fg">{{ $pathStr }}</span>@endif- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ number_format((int) ($path['requests'] ?? 0)) }} req</span>- <span class="shrink-0 text-[12px] text-neutral-500 dark:text-fg-dim">{{ formatBytes((int) ($path['bytesOut'] ?? 0)) }}</span>- <span class="hidden shrink-0 text-[12px] text-neutral-500 sm:inline dark:text-fg-dim">p95 {{ number_format((float) ($path['p95'] ?? 0), 1) }} ms</span>+ <div class="hidden h-1 w-16 shrink-0 overflow-hidden rounded-full bg-neutral-100 sm:block dark:bg-white/[0.06]">+ <div class="h-full rounded-full bg-[var(--chart-status-3xx)]" style="width: {{ $width }}%;"></div>+ </div>+ <span class="w-12 shrink-0 text-right text-[12px] font-medium tabular-nums text-black dark:text-fg"+ title="{{ number_format($requests) }} requests">{{ compactNumber($requests) }}</span>+ <span class="hidden w-16 shrink-0 text-right text-[11px] tabular-nums text-neutral-400 sm:inline dark:text-fg-faint">{{ formatBytes((int) ($path['bytesOut'] ?? 0)) }}</span>+ <span class="hidden w-16 shrink-0 text-right text-[11px] tabular-nums text-neutral-400 md:inline dark:text-fg-faint"+ title="p95 latency">{{ number_format((float) ($path['p95'] ?? 0), 1) }} ms</span></div>@endforeach@include('livewire.traffic._pager')diff --git a/resources/views/livewire/traffic/_sparkline.blade.php b/resources/views/livewire/traffic/_sparkline.blade.phpindex b484610b06..a296625568 100644--- a/resources/views/livewire/traffic/_sparkline.blade.php+++ b/resources/views/livewire/traffic/_sparkline.blade.php@@ -21,7 +21,27 @@const el = document.getElementById('{!! $id !!}');if (!el) { return; }- const cssVar = () => getComputedStyle(document.documentElement).getPropertyValue('{!! $colorVar !!}').trim() || '#3b82f6';+ const readVar = name => getComputedStyle(document.documentElement).getPropertyValue(name).trim();+ const accent = () => readVar('{!! $colorVar !!}') || '#3b82f6';+ const muted = () => readVar('--chart-geo-empty') || 'rgba(128,128,128,0.4)';++ // No/all-zero data → draw a flat muted baseline placeholder instead of a blank card.+ // A constant series with auto-scaling collapses to a degenerate (invisible) range,+ // so the placeholder pins the y-axis to keep the zero line centered and visible.+ const isFlat = a => !Array.isArray(a) || a.length === 0 || a.every(v => !Number(v));++ const apply = (values) => {+ const flat = isFlat(values);+ const len = Array.isArray(values) && values.length ? values.length : 12;+ chart.updateOptions({+ colors: [flat ? muted() : accent()],+ stroke: { width: flat ? 1 : 1.5, curve: 'smooth' },+ fill: { type: 'gradient', gradient: { opacityFrom: flat ? 0 : 0.35, opacityTo: 0 } },+ tooltip: { enabled: !flat },+ yaxis: flat ? { min: -1, max: 1 } : { min: undefined, max: undefined },+ }, false, false);+ chart.updateSeries([{ data: flat ? new Array(len).fill(0) : values }]);+ };const chart = new ApexCharts(el, {chart: {@@ -31,13 +51,10 @@animations: { enabled: false },background: 'transparent',},- series: [{ data: @json($initial) }],+ series: [{ data: [] }],stroke: { width: 1.5, curve: 'smooth' },- colors: [cssVar()],- fill: {- type: 'gradient',- gradient: { opacityFrom: 0.35, opacityTo: 0.02 },- },+ colors: [accent()],+ fill: { type: 'gradient', gradient: { opacityFrom: 0.35, opacityTo: 0.02 } },tooltip: {enabled: true,fixed: { enabled: false },@@ -47,14 +64,13 @@},});chart.render();+ apply(@json($initial));@if (! empty($event) && ! empty($key))Livewire.on('{!! $event !!}', payload => {const data = Array.isArray(payload) ? payload[0] : payload;- const next = data && data['{!! $key !!}'];- if (Array.isArray(next)) {- chart.updateOptions({ colors: [cssVar()] });- chart.updateSeries([{ data: next }]);+ if (data && '{!! $key !!}' in data) {+ apply(data['{!! $key !!}']);}});@endifdiff --git a/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.php b/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.phpindex 19e214e6c2..8952973601 100644--- a/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.php+++ b/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.php@@ -70,8 +70,8 @@ function fakeAnalyticsResponses(): array['value' => 'Desktop', 'requests' => 800, 'bytes_out' => 20000],]),'/traffic/series' => json_encode([- ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0],- ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1],+ ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0, 'requests' => 43, 'bytes_in' => 1000, 'bytes_out' => 5000, 'unique_visitors' => 12, 'p95' => 30.0],+ ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1, 'requests' => 66, 'bytes_in' => 1500, 'bytes_out' => 8000, 'unique_visitors' => 20, 'p95' => 45.0],]),'/traffic/attribution' => json_encode(['attribution' => 'GeoIP data by MaxMind']),];@@ -148,8 +148,8 @@ it('loads the per-app status time series when Sentinel exposes the series endpoi->assertOk()->assertSet('hasSeries', true)->assertSet('series', [- ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0],- ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1],+ ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0, 'requests' => 43, 'bytesIn' => 1000, 'bytesOut' => 5000, 'uniqueVisitors' => 12, 'p95' => 30.0],+ ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1, 'requests' => 66, 'bytesIn' => 1500, 'bytesOut' => 8000, 'uniqueVisitors' => 20, 'p95' => 45.0],])->assertDispatched('refreshChartData-application-analytics-status');});diff --git a/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.php b/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.phpindex 2ffc2569ac..f5a26f7bda 100644--- a/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.php+++ b/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.php@@ -81,8 +81,8 @@ function fakeGlobalAnalyticsResponses(array $appUuids = []): array['value' => '200', 'requests' => 900, 'bytes_out' => 22000],]),'/traffic/series' => json_encode([- ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0],- ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1],+ ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0, 'requests' => 43, 'bytes_in' => 1000, 'bytes_out' => 5000, 'unique_visitors' => 12, 'p95' => 30.0],+ ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1, 'requests' => 66, 'bytes_in' => 1500, 'bytes_out' => 8000, 'unique_visitors' => 20, 'p95' => 45.0],]),'/traffic/attribution' => json_encode(['attribution' => 'GeoIP data by MaxMind']),];@@ -211,8 +211,8 @@ it('builds a stacked status time series when Sentinel exposes the series endpoin->assertOk()->assertSet('hasSeries', true)->assertSet('series', [- ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0],- ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1],+ ['bucket' => 1_700_000_000_000, 's2xx' => 40, 's3xx' => 2, 's4xx' => 1, 's5xx' => 0, 'requests' => 43, 'bytesIn' => 1000, 'bytesOut' => 5000, 'uniqueVisitors' => 12, 'p95' => 30.0],+ ['bucket' => 1_700_003_600_000, 's2xx' => 60, 's3xx' => 3, 's4xx' => 2, 's5xx' => 1, 'requests' => 66, 'bytesIn' => 1500, 'bytesOut' => 8000, 'uniqueVisitors' => 20, 'p95' => 45.0],])->assertDispatched('refreshChartData-global-analytics-status');});@@ -239,9 +239,11 @@ it('derives KPI sparklines, device-donut data, and top hosts for the chart paylo$instance = Livewire::test(Analytics::class)->assertOk()->instance();- // Per-bucket totals and errors from the two-bucket status series.+ // Per-bucket sparkline series derived from Sentinel's enriched buckets.expect($instance->requestsSpark())->toBe([43, 66]);expect($instance->errorsSpark())->toBe([1, 3]);+ expect($instance->bandwidthSpark())->toBe([6000, 9500]);+ expect($instance->uniquesSpark())->toBe([12, 20]);// Device breakdown folds into donut labels/series.$device = $instance->deviceChartData();