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.

fix(metrics): pick the root disk on the server Metrics page like the Fleet page

Aditya Tripathif8ec00740334
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<int, array<string, mixed>> $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]];