From f8ec00740334ffb620b0bffb3fc7039ac4f86c49 Mon Sep 17 00:00:00 2001 From: Aditya Tripathi Date: Sat, 24 Oct 2026 06:35:52 +0000 Subject: [PATCH] fix(metrics): pick the root disk on the server Metrics page like the Fleet page The server Metrics page now uses SentinelMetricsClient::rootMountName(): /, else /app/db (Sentinel 1.1.2 and older), else /data/coolify or /data (Sentinel 1.1.3 and newer). Before, it kept only /, so the disk chart was empty when Sentinel did not report a / mount. --- app/Services/SentinelMetricsClient.php | 2 +- app/Traits/HasMetrics.php | 6 ++++-- tests/Unit/Metrics/HasMetricsMappingTest.php | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Services/SentinelMetricsClient.php b/app/Services/SentinelMetricsClient.php index 184c4bc4e7..fe3d785c63 100644 --- a/app/Services/SentinelMetricsClient.php +++ b/app/Services/SentinelMetricsClient.php @@ -184,7 +184,7 @@ class SentinelMetricsClient * * @param array> $rows */ - private static function rootMountName(array $rows): ?string + public static function rootMountName(array $rows): ?string { $mounts = array_column($rows, 'mount'); diff --git a/app/Traits/HasMetrics.php b/app/Traits/HasMetrics.php index a9fe454e3a..3a1648fc3f 100644 --- a/app/Traits/HasMetrics.php +++ b/app/Traits/HasMetrics.php @@ -3,6 +3,7 @@ namespace App\Traits; use App\Models\Server; +use App\Services\SentinelMetricsClient; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Support\Facades\Log; @@ -80,7 +81,7 @@ trait HasMetrics /** * Root filesystem usage percentage over time. Disk history interleaves every - * mount, so we keep only the root mount before mapping. + * mount, so we keep only the root mount (see SentinelMetricsClient::rootMountName()). */ public function getDiskMetrics(int $mins = 5): ?array { @@ -90,7 +91,8 @@ trait HasMetrics } if (array_any($rows, fn ($row) => array_key_exists('mount', $row))) { - $rows = array_values(array_filter($rows, fn ($row) => ($row['mount'] ?? null) === '/')); + $mount = SentinelMetricsClient::rootMountName($rows); + $rows = array_values(array_filter($rows, fn ($row) => ($row['mount'] ?? null) === $mount)); } return $this->mapRows($rows, 'usedPercent', $mins); diff --git a/tests/Unit/Metrics/HasMetricsMappingTest.php b/tests/Unit/Metrics/HasMetricsMappingTest.php index e1f2425343..e6c70be05b 100644 --- a/tests/Unit/Metrics/HasMetricsMappingTest.php +++ b/tests/Unit/Metrics/HasMetricsMappingTest.php @@ -74,6 +74,16 @@ it('does not use non-root mounts when root disk samples are missing', function ( expect($double->getDiskMetrics(5))->toBe([]); }); +it('uses the Sentinel data mount for disk metrics when no root mount is reported', function () { + $double = new MetricsMappingDouble; + $double->rowsByType['disk'] = [ + ['time' => 1000, 'mount' => '/boot', 'usedPercent' => 90], + ['time' => 1000, 'mount' => '/app/db', 'usedPercent' => 30], + ]; + + expect($double->getDiskMetrics(5))->toBe([[1000, 30.0]]); +}); + it('supports older disk rows without a mount field', function () { $double = new MetricsMappingDouble; $double->rowsByType['disk'] = [['time' => 1000, 'usedPercent' => 40]];