Skip to content

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.

feat(traffic): split traffic chart into requests and status codes

Aditya Tripathib436a7a81478
diff --git a/app/Livewire/Analytics.php b/app/Livewire/Analytics.php
index 6c82ceb0db..236cd40bc1 100644
--- a/app/Livewire/Analytics.php
+++ b/app/Livewire/Analytics.php
@@ -404,6 +404,7 @@ class Analytics extends Component
],
'timeSeries' => [
'categories' => array_column($this->series, 'bucket'),
+ 'requests' => $this->requestsSpark(),
's2xx' => array_column($this->series, 's2xx'),
's3xx' => array_column($this->series, 's3xx'),
's4xx' => array_column($this->series, 's4xx'),
@@ -413,6 +414,7 @@ class Analytics extends Component
'errorsSpark' => $this->errorsSpark(),
'bandwidthSpark' => $this->bandwidthSpark(),
'uniquesSpark' => $this->uniquesSpark(),
+ 'latencySpark' => $this->latencySpark(),
'geo' => $this->geoMarkers(),
'deviceLabels' => $device['labels'],
'deviceSeries' => $device['series'],
diff --git a/app/Livewire/Concerns/BuildsTrafficChartPayload.php b/app/Livewire/Concerns/BuildsTrafficChartPayload.php
index 40b7f6cb07..6963cfd0ad 100644
--- a/app/Livewire/Concerns/BuildsTrafficChartPayload.php
+++ b/app/Livewire/Concerns/BuildsTrafficChartPayload.php
@@ -62,6 +62,16 @@ trait BuildsTrafficChartPayload
return array_map(fn ($b) => (int) ($b['uniqueVisitors'] ?? 0), $this->series);
}
+ /**
+ * Per-bucket p95 latency (ms), for the Latency spark.
+ *
+ * @return array<int, float>
+ */
+ public function latencySpark(): array
+ {
+ return array_map(fn ($b) => round((float) ($b['p95'] ?? 0), 1), $this->series);
+ }
+
/**
* Per-country marker data for the globe: [{code, requests}] over known ISO-A2 rows.
*
diff --git a/app/Livewire/Project/Application/Analytics.php b/app/Livewire/Project/Application/Analytics.php
index 6e8123a626..2496ba3187 100644
--- a/app/Livewire/Project/Application/Analytics.php
+++ b/app/Livewire/Project/Application/Analytics.php
@@ -145,6 +145,7 @@ class Analytics extends Component
],
'timeSeries' => [
'categories' => array_column($this->series, 'bucket'),
+ 'requests' => $this->requestsSpark(),
's2xx' => array_column($this->series, 's2xx'),
's3xx' => array_column($this->series, 's3xx'),
's4xx' => array_column($this->series, 's4xx'),
@@ -154,6 +155,7 @@ class Analytics extends Component
'errorsSpark' => $this->errorsSpark(),
'bandwidthSpark' => $this->bandwidthSpark(),
'uniquesSpark' => $this->uniquesSpark(),
+ 'latencySpark' => $this->latencySpark(),
'geo' => $this->geoMarkers(),
'deviceLabels' => $device['labels'],
'deviceSeries' => $device['series'],
diff --git a/resources/views/livewire/analytics.blade.php b/resources/views/livewire/analytics.blade.php
index 19c1524642..98d505b110 100644
--- a/resources/views/livewire/analytics.blade.php
+++ b/resources/views/livewire/analytics.blade.php
@@ -193,15 +193,29 @@ $appListboxOptions = array_merge(
@endif
</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 class="mt-auto pt-3">
+ @include('livewire.traffic._sparkline', [
+ 'id' => $chartId.'-spark-latency',
+ 'initial' => $this->latencySpark(),
+ 'colorVar' => '--chart-status-4xx',
+ 'event' => 'refreshChartData-'.$chartId.'-status',
+ 'key' => 'latencySpark',
+ ])
+ </div>
</div>
</div>
</x-application.settings-section>
- {{-- Traffic over time (stacked area), or a status donut when Sentinel lacks /traffic/series. --}}
- <x-application.settings-section id="analytics-status-section" title="Traffic"
- helper="Request volume by status class over time for the selected range.">
- @include('livewire.traffic._status-chart')
+ {{-- Requests over time (single area series). --}}
+ <x-application.settings-section id="analytics-requests-section" title="Requests"
+ helper="Total request volume over time for the selected range.">
+ @include('livewire.traffic._requests-chart')
+ </x-application.settings-section>
+
+ {{-- Status codes: stacked bar of responses by status class. --}}
+ <x-application.settings-section id="analytics-status-codes-section" title="Status codes"
+ helper="Share of responses by HTTP status class for the selected range.">
+ @include('livewire.traffic._status-codes')
</x-application.settings-section>
{{-- Top applications + Top hosts side by side; Top paths spans full width below.
diff --git a/resources/views/livewire/project/application/analytics.blade.php b/resources/views/livewire/project/application/analytics.blade.php
index e7cdda83db..edbc4ccc69 100644
--- a/resources/views/livewire/project/application/analytics.blade.php
+++ b/resources/views/livewire/project/application/analytics.blade.php
@@ -117,14 +117,27 @@ $analyticsServerUuid = $application->destination?->server?->uuid;
<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="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 class="mt-auto pt-3">
+ @include('livewire.traffic._sparkline', [
+ 'id' => $chartId.'-spark-latency',
+ 'initial' => $this->latencySpark(),
+ 'colorVar' => '--chart-status-4xx',
+ 'event' => 'refreshChartData-'.$chartId.'-status',
+ 'key' => 'latencySpark',
+ ])
+ </div>
</div>
</div>
</x-application.settings-section>
- <x-application.settings-section id="analytics-status-section" title="Traffic"
- helper="Request volume by status class over time for the selected range.">
- @include('livewire.traffic._status-chart')
+ <x-application.settings-section id="analytics-requests-section" title="Requests"
+ helper="Total request volume over time for the selected range.">
+ @include('livewire.traffic._requests-chart')
+ </x-application.settings-section>
+
+ <x-application.settings-section id="analytics-status-codes-section" title="Status codes"
+ helper="Share of responses by HTTP status class for the selected range.">
+ @include('livewire.traffic._status-codes')
</x-application.settings-section>
<x-application.settings-section id="analytics-paths-section" title="Top paths"
diff --git a/resources/views/livewire/traffic/_device-chart.blade.php b/resources/views/livewire/traffic/_device-chart.blade.php
index 4dba309979..44ca9c092b 100644
--- a/resources/views/livewire/traffic/_device-chart.blade.php
+++ b/resources/views/livewire/traffic/_device-chart.blade.php
@@ -36,7 +36,10 @@
dataLabels: { enabled: false },
legend: legend(),
plotOptions: { pie: { donut: { size: '68%' } } },
- tooltip: { y: { formatter: v => `${v.toLocaleString()} requests` } },
+ {{-- Donuts otherwise fill the whole tooltip with the slice color (white
+ text on light slices reads poorly); fillSeriesColor:false gives the
+ same neutral tooltip the other charts use. --}}
+ tooltip: { fillSeriesColor: false, y: { formatter: v => `${v.toLocaleString()} requests` } },
noData: { text: 'Loading devices…', style: { color: textColor } },
});
chart.render();
diff --git a/resources/views/livewire/traffic/_live-toggle.blade.php b/resources/views/livewire/traffic/_live-toggle.blade.php
index 87f48daa8a..3169807e7b 100644
--- a/resources/views/livewire/traffic/_live-toggle.blade.php
+++ b/resources/views/livewire/traffic/_live-toggle.blade.php
@@ -1,31 +1,30 @@
{{--
- Sentry-style play/pause control for realtime analytics refresh. Sits next to the
- time-range selector. Live is only meaningful at the 24h range (minute-level rollups),
- so the control is disabled for 7d/30d. The choice is persisted per-browser in
- localStorage. Expects `$range` in scope and a `live` bool + `toggleLive()` on the host
- Livewire component. The pulsing dot respects prefers-reduced-motion.
+ "Live Refresh" toggle for realtime analytics. Sits next to the time-range selector.
+ Realtime is only meaningful at the 24h range (minute-level rollups), so the control
+ is hidden entirely for 7d/30d. The label is constant; the active state is shown by the
+ button color + a pulsing emerald dot. The choice is persisted per-browser in
+ localStorage. Expects `$range` in scope and a `live` bool on the host Livewire component.
+ The pulse respects prefers-reduced-motion.
--}}
-@php $liveEnabled = $range === '24h'; @endphp
-<div x-data="{ live: $wire.entangle('live').live }"
- x-init="
- if (localStorage.getItem('traffic-live') === '0') { live = false; }
- $watch('live', value => localStorage.setItem('traffic-live', value ? '1' : '0'));
- ">
- <button type="button"
- @click="live = !live"
- @disabled(! $liveEnabled)
- title="{{ $liveEnabled ? 'Toggle realtime refresh (updates every 60s)' : 'Realtime refresh is only available for the 24h range' }}"
- class="inline-flex h-7 items-center gap-1.5 rounded-md px-2.5 text-[12px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40 ring-1 ring-neutral-200 dark:ring-white/[0.08]"
- :class="live
- ? 'bg-white text-black shadow-sm dark:bg-white/[0.09] dark:text-fg'
- : 'text-neutral-500 hover:text-black dark:text-fg-faint dark:hover:text-fg'">
- <span x-show="live" class="relative flex h-1.5 w-1.5 shrink-0" aria-hidden="true">
- <span class="absolute inline-flex h-full w-full rounded-full bg-emerald-500 opacity-75 motion-safe:animate-ping"></span>
- <span class="relative inline-flex h-1.5 w-1.5 rounded-full bg-emerald-500"></span>
- </span>
- <svg x-show="!live" class="h-3 w-3 shrink-0" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
- <path d="M8 5v14l11-7z" />
- </svg>
- <span x-text="live ? 'Live' : 'Paused'">Live</span>
- </button>
-</div>
+@if ($range === '24h')
+ <div x-data="{ live: $wire.entangle('live').live }"
+ x-init="
+ if (localStorage.getItem('traffic-live') === '0') { live = false; }
+ $watch('live', value => localStorage.setItem('traffic-live', value ? '1' : '0'));
+ ">
+ <button type="button"
+ @click="live = !live"
+ :aria-pressed="live ? 'true' : 'false'"
+ title="Toggle realtime refresh (updates every 60s)"
+ class="inline-flex h-7 items-center gap-1.5 rounded-md px-2.5 text-[12px] font-medium ring-1 transition-colors"
+ :class="live
+ ? 'bg-white text-black shadow-sm ring-neutral-200 dark:bg-white/[0.09] dark:text-fg dark:ring-white/[0.08]'
+ : 'text-neutral-500 ring-neutral-200 hover:text-black dark:text-fg-faint dark:ring-white/[0.08] dark:hover:text-fg'">
+ <span class="relative flex h-1.5 w-1.5 shrink-0" aria-hidden="true">
+ <span x-show="live" class="absolute inline-flex h-full w-full rounded-full bg-emerald-500 opacity-75 motion-safe:animate-ping"></span>
+ <span class="relative inline-flex h-1.5 w-1.5 rounded-full" :class="live ? 'bg-emerald-500' : 'bg-neutral-400 dark:bg-white/40'"></span>
+ </span>
+ <span>Live Refresh</span>
+ </button>
+ </div>
+@endif
diff --git a/resources/views/livewire/traffic/_requests-chart.blade.php b/resources/views/livewire/traffic/_requests-chart.blade.php
new file mode 100644
index 0000000000..c38f5cc460
--- /dev/null
+++ b/resources/views/livewire/traffic/_requests-chart.blade.php
@@ -0,0 +1,86 @@
+{{--
+ Requests-over-time chart: a single area series of total requests per bucket for the
+ selected range. Reads its accent color from the shared --chart-status-3xx design
+ token. Updated via the `refreshChartData-{chartId}-status` event (the `timeSeries.requests`
+ array, aligned with `timeSeries.categories`). Expects `$chartId` in scope.
+--}}
+<div wire:ignore id="{!! $chartId !!}-requests" class="min-h-[220px] w-full"></div>
+
+@script
+<script>
+ (() => {
+ checkTheme();
+
+ const el = document.getElementById('{!! $chartId !!}-requests');
+ const cssVar = name => getComputedStyle(document.documentElement).getPropertyValue(name).trim();
+ const accent = () => cssVar('--chart-status-3xx') || '#3b82f6';
+ const gridColor = () => cssVar('--chart-geo-empty') || 'rgba(128,128,128,0.15)';
+
+ // `24h` buckets are hourly, `7d`/`30d` daily — pick a matching axis/tooltip format.
+ const timeFormat = range => (range === '24h' ? 'HH:mm' : 'dd MMM');
+
+ const chart = new ApexCharts(el, {
+ chart: {
+ height: 220,
+ type: 'area',
+ toolbar: { show: false },
+ zoom: { enabled: false },
+ animations: { enabled: false },
+ background: 'transparent',
+ },
+ series: [{ name: 'Requests', data: [] }],
+ colors: [accent()],
+ dataLabels: { enabled: false },
+ stroke: { width: 2, curve: 'smooth' },
+ fill: {
+ type: 'gradient',
+ gradient: { opacityFrom: 0.35, opacityTo: 0.05 },
+ },
+ xaxis: {
+ type: 'datetime',
+ labels: { style: { colors: textColor }, datetimeUTC: false },
+ axisBorder: { show: false },
+ axisTicks: { show: false },
+ },
+ yaxis: {
+ labels: {
+ style: { colors: textColor },
+ formatter: value => Math.round(value).toLocaleString(),
+ },
+ },
+ grid: { borderColor: gridColor() },
+ legend: { show: false },
+ noData: {
+ text: 'Loading requests…',
+ style: { color: textColor },
+ },
+ tooltip: {
+ y: {
+ formatter: value => `${value.toLocaleString()} requests`,
+ },
+ },
+ });
+ chart.render();
+
+ Livewire.on('refreshChartData-{!! $chartId !!}-status', payload => {
+ checkTheme();
+ const data = Array.isArray(payload) ? payload[0] : payload;
+ if (!data || !data.timeSeries) { return; }
+
+ const ts = data.timeSeries;
+ const points = (ts.categories || []).map((c, i) => ({ x: c, y: (ts.requests && ts.requests[i]) || 0 }));
+
+ chart.updateOptions({
+ colors: [accent()],
+ grid: { borderColor: gridColor() },
+ xaxis: {
+ type: 'datetime',
+ labels: { style: { colors: textColor }, datetimeUTC: false, format: timeFormat(data.range) },
+ },
+ tooltip: { x: { format: timeFormat(data.range) } },
+ });
+ chart.updateSeries([{ name: 'Requests', data: points }]);
+ });
+ })();
+</script>
+@endscript
diff --git a/resources/views/livewire/traffic/_sparkline.blade.php b/resources/views/livewire/traffic/_sparkline.blade.php
index a296625568..f868c2b1f4 100644
--- a/resources/views/livewire/traffic/_sparkline.blade.php
+++ b/resources/views/livewire/traffic/_sparkline.blade.php
@@ -1,7 +1,15 @@
{{--
Tiny inline sparkline for a KPI stat card. Renders an axis-less ApexCharts area
- spark from a numeric series, and (when an event name is given) live-updates from
- the host component's chart payload so range/live refreshes stay in sync.
+ spark from a numeric series and (when an event name is given) live-updates from the
+ host component's chart payload so range/live refreshes stay in sync.
+
+ Initialized via Alpine (not Livewire's @script): this partial is @include'd several
+ times per page, and Livewire dedupes identical @script blocks from the same compiled
+ view — so all but the last sparkline would silently never initialize. Alpine's
+ init() runs once per element, with no such dedup.
+
+ A no-data / all-zero series draws a flat muted baseline (a constant series with
+ auto-scaling collapses to a degenerate, invisible range, so the y-axis is pinned).
@param string $id unique DOM id for this spark
@param array $initial initial numeric series (server-rendered first paint)
@@ -12,68 +20,55 @@
@php
$initial = $initial ?? [];
$colorVar = $colorVar ?? '--chart-status-3xx';
+ $event = $event ?? '';
+ $key = $key ?? '';
@endphp
-<div wire:ignore id="{!! $id !!}" class="h-9 w-full"></div>
-
-@script
-<script>
- (() => {
- const el = document.getElementById('{!! $id !!}');
- if (!el) { return; }
-
- 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()],
+<div wire:ignore id="{!! $id !!}" class="h-9 w-full"
+ x-data="{
+ chart: null,
+ accent() { return getComputedStyle(document.documentElement).getPropertyValue('{{ $colorVar }}').trim() || '#3b82f6'; },
+ muted() { return getComputedStyle(document.documentElement).getPropertyValue('--chart-geo-empty').trim() || 'rgba(128,128,128,0.45)'; },
+ isFlat(a) { return !Array.isArray(a) || a.length === 0 || a.every(v => !Number(v)); },
+ opts(values) {
+ const flat = this.isFlat(values);
+ const len = (Array.isArray(values) && values.length) ? values.length : 12;
+ return {
+ series: [{ data: flat ? Array(len).fill(0) : values }],
+ colors: [flat ? this.muted() : this.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: {
- type: 'area',
- height: 36,
- sparkline: { enabled: true },
- animations: { enabled: false },
- background: 'transparent',
- },
- series: [{ data: [] }],
- stroke: { width: 1.5, curve: 'smooth' },
- colors: [accent()],
- fill: { type: 'gradient', gradient: { opacityFrom: 0.35, opacityTo: 0.02 } },
- tooltip: {
- enabled: true,
- fixed: { enabled: false },
- x: { show: false },
- y: { formatter: v => `${Math.round(v).toLocaleString()}`, title: { formatter: () => '' } },
- marker: { show: false },
- },
- });
- chart.render();
- apply(@json($initial));
-
- @if (! empty($event) && ! empty($key))
- Livewire.on('{!! $event !!}', payload => {
- const data = Array.isArray(payload) ? payload[0] : payload;
- if (data && '{!! $key !!}' in data) {
- apply(data['{!! $key !!}']);
- }
+ yaxis: flat ? { min: -1, max: 1 } : {},
+ };
+ },
+ init() {
+ if (typeof ApexCharts === 'undefined') { return; }
+ const o = this.opts(@js($initial));
+ this.chart = new ApexCharts($el, {
+ chart: { type: 'area', height: 36, sparkline: { enabled: true }, animations: { enabled: false }, background: 'transparent' },
+ series: o.series,
+ colors: o.colors,
+ stroke: o.stroke,
+ fill: o.fill,
+ yaxis: o.yaxis,
+ tooltip: {
+ enabled: o.tooltip.enabled,
+ fixed: { enabled: false },
+ x: { show: false },
+ y: { formatter: v => Math.round(v).toLocaleString(), title: { formatter: () => '' } },
+ marker: { show: false },
+ },
});
- @endif
- })();
-</script>
-@endscript
+ this.chart.render();
+ @if ($event && $key)
+ Livewire.on('{{ $event }}', payload => {
+ const data = Array.isArray(payload) ? payload[0] : payload;
+ if (this.chart && data && '{{ $key }}' in data) {
+ const u = this.opts(data['{{ $key }}']);
+ this.chart.updateOptions({ colors: u.colors, stroke: u.stroke, fill: u.fill, tooltip: { enabled: u.tooltip.enabled }, yaxis: u.yaxis }, false, false);
+ this.chart.updateSeries(u.series);
+ }
+ });
+ @endif
+ },
+ }"></div>
diff --git a/resources/views/livewire/traffic/_status-chart.blade.php b/resources/views/livewire/traffic/_status-chart.blade.php
deleted file mode 100644
index a25f9fda78..0000000000
--- a/resources/views/livewire/traffic/_status-chart.blade.php
+++ /dev/null
@@ -1,144 +0,0 @@
-{{--
- Status-class chart. Renders a stacked area chart of per-bucket 2xx/3xx/4xx/5xx
- counts over time when Sentinel exposes the /traffic/series endpoint, and falls
- back to a status donut when it does not (older Sentinel returns 404, so the host
- component dispatches `hasSeries: false`). Colors read from the shared --chart-status-*
- design tokens. Expects `$chartId` in scope.
---}}
-<div wire:ignore id="{!! $chartId !!}-status" class="min-h-[220px] w-full"></div>
-
-@script
-<script>
- (() => {
- checkTheme();
-
- const el = document.getElementById('{!! $chartId !!}-status');
- const cssVar = name => getComputedStyle(document.documentElement).getPropertyValue(name).trim();
- const statusColors = () => [
- cssVar('--chart-status-2xx'),
- cssVar('--chart-status-3xx'),
- cssVar('--chart-status-4xx'),
- cssVar('--chart-status-5xx'),
- ];
- const gridColor = () => cssVar('--chart-geo-empty') || 'rgba(128,128,128,0.15)';
-
- const legend = () => ({
- position: 'bottom',
- labels: {
- colors: textColor,
- },
- });
-
- const buildDonut = () => new ApexCharts(el, {
- chart: {
- height: 220,
- type: 'donut',
- toolbar: { show: false },
- background: 'transparent',
- },
- series: [0, 0, 0, 0],
- labels: ['2xx', '3xx', '4xx', '5xx'],
- colors: statusColors(),
- stroke: { width: 2 },
- dataLabels: { enabled: false },
- legend: legend(),
- noData: {
- text: 'Loading status codes…',
- style: { color: textColor },
- },
- tooltip: {
- y: {
- formatter: value => `${value.toLocaleString()} requests`,
- },
- },
- });
-
- // `24h` buckets are hourly, `7d`/`30d` daily — pick a matching axis/tooltip format.
- const timeFormat = range => (range === '24h' ? 'HH:mm' : 'dd MMM');
-
- const buildArea = () => new ApexCharts(el, {
- chart: {
- height: 220,
- type: 'area',
- stacked: true,
- toolbar: { show: false },
- zoom: { enabled: false },
- animations: { enabled: false },
- background: 'transparent',
- },
- series: [],
- colors: statusColors(),
- dataLabels: { enabled: false },
- stroke: { width: 2, curve: 'smooth' },
- fill: {
- type: 'gradient',
- gradient: { opacityFrom: 0.35, opacityTo: 0.05 },
- },
- xaxis: {
- type: 'datetime',
- labels: { style: { colors: textColor }, datetimeUTC: false },
- axisBorder: { show: false },
- axisTicks: { show: false },
- },
- yaxis: {
- labels: {
- style: { colors: textColor },
- formatter: value => Math.round(value).toLocaleString(),
- },
- },
- grid: { borderColor: gridColor() },
- legend: legend(),
- noData: {
- text: 'Loading status codes…',
- style: { color: textColor },
- },
- tooltip: {
- y: {
- formatter: value => `${value.toLocaleString()} requests`,
- },
- },
- });
-
- let chart = buildDonut();
- let mode = 'donut';
- chart.render();
-
- Livewire.on('refreshChartData-{!! $chartId !!}-status', payload => {
- checkTheme();
- const data = Array.isArray(payload) ? payload[0] : payload;
- const wantArea = !!(data && data.hasSeries && data.timeSeries);
- const nextMode = wantArea ? 'area' : 'donut';
-
- if (nextMode !== mode) {
- chart.destroy();
- chart = nextMode === 'area' ? buildArea() : buildDonut();
- chart.render();
- mode = nextMode;
- }
-
- if (nextMode === 'area') {
- chart.updateOptions({
- colors: statusColors(),
- grid: { borderColor: gridColor() },
- legend: legend(),
- xaxis: {
- type: 'datetime',
- categories: data.timeSeries.categories,
- labels: { style: { colors: textColor }, datetimeUTC: false, format: timeFormat(data.range) },
- },
- tooltip: { x: { format: timeFormat(data.range) } },
- });
- chart.updateSeries([
- { name: '2xx', data: data.timeSeries.s2xx },
- { name: '3xx', data: data.timeSeries.s3xx },
- { name: '4xx', data: data.timeSeries.s4xx },
- { name: '5xx', data: data.timeSeries.s5xx },
- ]);
- } else {
- chart.updateOptions({ colors: statusColors(), legend: legend() });
- chart.updateSeries(data.seriesData);
- }
- });
- })();
-</script>
-@endscript
diff --git a/resources/views/livewire/traffic/_status-codes.blade.php b/resources/views/livewire/traffic/_status-codes.blade.php
new file mode 100644
index 0000000000..0c6928b390
--- /dev/null
+++ b/resources/views/livewire/traffic/_status-codes.blade.php
@@ -0,0 +1,71 @@
+{{--
+ Status-codes summary: a single horizontal stacked bar of responses by HTTP status
+ class (2xx / 3xx / 4xx / 5xx) with a legend of per-class counts, driven by the
+ overview totals. Plain server-rendered markup — it updates via Livewire morph on
+ range/live refresh. Hovering a segment shows a cursor-following tooltip styled to
+ match the ApexCharts charts. Colors are inlined (categorical, theme-neutral) so the
+ bar reads the same in light and dark. Expects `$overview` in scope.
+--}}
+@php
+ $codes = [
+ ['label' => '2xx', 'count' => (int) ($overview['s2xx'] ?? 0), 'color' => '#3b82f6'],
+ ['label' => '3xx', 'count' => (int) ($overview['s3xx'] ?? 0), 'color' => '#eab308'],
+ ['label' => '4xx', 'count' => (int) ($overview['s4xx'] ?? 0), 'color' => '#ec4899'],
+ ['label' => '5xx', 'count' => (int) ($overview['s5xx'] ?? 0), 'color' => '#a855f7'],
+ ];
+ $total = array_sum(array_column($codes, 'count'));
+@endphp
+
+<div class="flex flex-col gap-3"
+ x-data="{
+ tip: { show: false, x: 0, y: 0, label: '', count: '', pct: '', color: '' },
+ show(e, label, count, pct, color) {
+ this.tip.label = label; this.tip.count = count; this.tip.pct = pct; this.tip.color = color;
+ this.tip.x = e.clientX; this.tip.y = e.clientY; this.tip.show = true;
+ },
+ move(e) { this.tip.x = e.clientX; this.tip.y = e.clientY; },
+ }">
+ {{-- Legend --}}
+ <div class="flex flex-wrap items-center gap-x-5 gap-y-2">
+ @foreach ($codes as $code)
+ <div class="flex items-center gap-1.5">
+ <span class="h-2 w-2 shrink-0 rounded-full" style="background-color: {{ $code['color'] }};" aria-hidden="true"></span>
+ <span class="text-[12px] text-neutral-500 dark:text-fg-dim">{{ $code['label'] }}</span>
+ <span class="text-[12px] font-semibold tabular-nums text-black dark:text-fg"
+ title="{{ number_format($code['count']) }} responses">{{ compactNumber($code['count']) }}</span>
+ </div>
+ @endforeach
+ </div>
+
+ {{-- Stacked proportional bar --}}
+ @if ($total > 0)
+ <div class="flex h-7 w-full overflow-hidden rounded-md bg-neutral-100 dark:bg-white/[0.06]">
+ @foreach ($codes as $code)
+ @if ($code['count'] > 0)
+ @php $pct = round($code['count'] / $total * 100, 1); @endphp
+ <div class="h-full cursor-default"
+ style="width: {{ round($code['count'] / $total * 100, 3) }}%; background-color: {{ $code['color'] }}; transition: filter 0.12s ease;"
+ @mouseenter="show($event, '{{ $code['label'] }}', '{{ number_format($code['count']) }}', '{{ $pct }}%', '{{ $code['color'] }}'); $el.style.filter = 'brightness(1.12)'"
+ @mousemove="move($event)"
+ @mouseleave="tip.show = false; $el.style.filter = ''"></div>
+ @endif
+ @endforeach
+ </div>
+
+ {{-- Cursor-following tooltip (matches the ApexCharts tooltip look). --}}
+ <div x-show="tip.show" x-cloak x-transition.opacity.duration.100ms
+ :style="`left: ${tip.x + 14}px; top: ${tip.y + 14}px;`"
+ class="pointer-events-none fixed z-[100] rounded-lg border border-neutral-700 bg-neutral-900 px-2.5 py-1.5 text-white shadow-lg">
+ <div class="flex items-center gap-1.5 text-[12px] font-medium">
+ <span class="h-2 w-2 shrink-0 rounded-full" :style="`background-color: ${tip.color};`" aria-hidden="true"></span>
+ <span x-text="tip.label"></span>
+ </div>
+ <div class="mt-0.5 text-[11px] text-neutral-300">
+ <span x-text="tip.count"></span> responses · <span x-text="tip.pct"></span>
+ </div>
+ </div>
+ @else
+ <x-empty size="sm" title="No status data" description="No responses were recorded for the selected range."
+ icon-name="network" />
+ @endif
+</div>
diff --git a/tests/Feature/TrafficAnalytics/ChartTokensTest.php b/tests/Feature/TrafficAnalytics/ChartTokensTest.php
index a84db8e3cb..5d0bc265bb 100644
--- a/tests/Feature/TrafficAnalytics/ChartTokensTest.php
+++ b/tests/Feature/TrafficAnalytics/ChartTokensTest.php
@@ -37,14 +37,14 @@ it('no longer hardcodes status color hex arrays in the analytics views', functio
expect($contents)->not->toContain('statusColorsLight');
expect($contents)->not->toContain('statusColorsDark');
// The chart lives in the shared partial; the views just pull it in.
- expect($contents)->toContain("@include('livewire.traffic._status-chart')");
+ expect($contents)->toContain("@include('livewire.traffic._requests-chart')");
}
});
-it('reads status colors from design tokens in the shared status-chart partial', function () {
- $partial = file_get_contents(base_path('resources/views/livewire/traffic/_status-chart.blade.php'));
+it('reads its accent color from a design token in the shared requests-chart partial', function () {
+ $partial = file_get_contents(base_path('resources/views/livewire/traffic/_requests-chart.blade.php'));
expect($partial)->not->toContain('statusColorsLight');
expect($partial)->not->toContain('statusColorsDark');
- expect($partial)->toContain('--chart-status-2xx');
+ expect($partial)->toContain('--chart-status-3xx');
});
diff --git a/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.php b/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.php
index f5a26f7bda..fc64e4c333 100644
--- a/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.php
+++ b/tests/Feature/TrafficAnalytics/GlobalAnalyticsTest.php
@@ -137,6 +137,7 @@ it('renders a team-wide analytics summary across enabled servers', function () {
->assertSee('Global Leaderboard App')
->assertSee('Top hosts')
->assertSee('Top paths')
+ ->assertSee('Status codes')
->assertSee('Countries')
->assertSee('United States')
// New breakdown sections surfaced from previously-unused Sentinel dimensions.
@@ -244,6 +245,7 @@ it('derives KPI sparklines, device-donut data, and top hosts for the chart paylo
expect($instance->errorsSpark())->toBe([1, 3]);
expect($instance->bandwidthSpark())->toBe([6000, 9500]);
expect($instance->uniquesSpark())->toBe([12, 20]);
+ expect($instance->latencySpark())->toBe([30.0, 45.0]);
// Device breakdown folds into donut labels/series.
$device = $instance->deviceChartData();
diff --git a/tests/Feature/TrafficAnalytics/LiveRefreshTest.php b/tests/Feature/TrafficAnalytics/LiveRefreshTest.php
index 1a2cbde2e6..7d47045c25 100644
--- a/tests/Feature/TrafficAnalytics/LiveRefreshTest.php
+++ b/tests/Feature/TrafficAnalytics/LiveRefreshTest.php
@@ -52,14 +52,14 @@ function bootLiveServer(): Server
return $server;
}
-it('is paused by default and does not poll until Live is turned on', function () {
+it('is paused by default and does not poll until Live Refresh is turned on', function () {
$server = bootLiveServer();
Livewire::test(Analytics::class)
->assertOk()
->assertSet('live', false)
->assertDontSeeHtml('wire:poll.60s')
- ->assertSee('Paused');
+ ->assertSee('Live Refresh');
});
it('starts polling when live is toggled on at the 24h range', function () {
@@ -70,22 +70,22 @@ it('starts polling when live is toggled on at the 24h range', function () {
->call('toggleLive')
->assertSet('live', true)
->assertSeeHtml('wire:poll.60s')
- ->assertSee('Live');
+ ->assertSee('Live Refresh');
});
-it('disables realtime polling for the 7d and 30d ranges', function () {
+it('hides the Live Refresh control and stops polling for the 7d and 30d ranges', function () {
$server = bootLiveServer();
$component = Livewire::test(Analytics::class)
->call('setRange', '7d')
- ->assertDontSeeHtml('wire:poll.60s');
+ ->assertDontSeeHtml('wire:poll.60s')
+ ->assertDontSee('Live Refresh');
expect($component->instance()->isLivePollable())->toBeFalse();
- // toggleLive is a no-op outside the 24h range.
- $component->call('toggleLive')->assertDontSeeHtml('wire:poll.60s');
-
- $component->call('setRange', '30d')->assertDontSeeHtml('wire:poll.60s');
+ $component->call('setRange', '30d')
+ ->assertDontSeeHtml('wire:poll.60s')
+ ->assertDontSee('Live Refresh');
});
it('re-arms polling when returning to the 24h range after live was turned on', function () {