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.
This commit is contained in:
Aditya Tripathi
2026-10-27 09:54:29 +01:00
committed by Andras Bacsai
parent 5312ea4dbc
commit f8ec007403
3 changed files with 15 additions and 3 deletions
+1 -1
View File
@@ -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');
+4 -2
View File
@@ -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);
@@ -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]];