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(dashboard): stop unreachable servers from blocking metrics charts

Andras Bacsai65c4c430fc21
diff --git a/app/Livewire/Dashboard/ServerMetricsChart.php b/app/Livewire/Dashboard/ServerMetricsChart.php
index fce9460064..83748052ce 100644
--- a/app/Livewire/Dashboard/ServerMetricsChart.php
+++ b/app/Livewire/Dashboard/ServerMetricsChart.php
@@ -4,14 +4,23 @@ namespace App\Livewire\Dashboard;
use App\Models\Server;
use Illuminate\Contracts\View\View;
+use Livewire\Attributes\Isolate;
use Livewire\Component;
+/**
+ * Each chart sends its own request, so one slow server does not delay the charts of the other servers.
+ */
+#[Isolate]
class ServerMetricsChart extends Component
{
public Server $server;
public function loadData(): void
{
+ if (! $this->server->isFunctional()) {
+ return;
+ }
+
try {
$this->dispatch("dashboard-server-metrics-{$this->server->uuid}", [
'cpu' => $this->server->getCpuMetrics(10),
diff --git a/tests/Feature/DashboardServerMetricsChartTest.php b/tests/Feature/DashboardServerMetricsChartTest.php
index eecae59f24..f5e1522757 100644
--- a/tests/Feature/DashboardServerMetricsChartTest.php
+++ b/tests/Feature/DashboardServerMetricsChartTest.php
@@ -1,6 +1,7 @@
<?php
use App\Livewire\Dashboard;
+use App\Livewire\Dashboard\ServerMetricsChart;
use App\Livewire\Server\Index as ServerIndex;
use App\Models\InstanceSettings;
use App\Models\PrivateKey;
@@ -8,12 +9,14 @@ use App\Models\Server;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Queue;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
+ Server::flushIdentityMap();
Queue::fake();
InstanceSettings::unguarded(fn () => InstanceSettings::query()->create(['id' => 0]));
@@ -63,3 +66,41 @@ it('renders dashboard metrics charts on the server index grid', function () {
->assertSeeHtml("dashboard-server-metrics-{$enabledServer->uuid}")
->assertDontSeeHtml("dashboard-server-metrics-{$disabledServer->uuid}");
});
+
+it('does not run SSH for an unreachable server when loading dashboard metrics', function () {
+ Process::fake();
+
+ $server = Server::factory()->create([
+ 'team_id' => $this->team->id,
+ 'private_key_id' => $this->privateKey->id,
+ ]);
+ $server->settings->update(['is_metrics_enabled' => true, 'is_reachable' => false]);
+
+ Livewire::test(ServerMetricsChart::class, ['server' => $server->fresh()])
+ ->call('loadData')
+ ->assertNotDispatched("dashboard-server-metrics-{$server->uuid}");
+
+ Process::assertNothingRan();
+});
+
+it('loads dashboard metrics over SSH for a reachable server', function () {
+ Process::fake(['*' => Process::result(output: '[{"time":1700000000000,"percent":12.5,"usedPercent":40}]')]);
+
+ $server = Server::factory()->create([
+ 'team_id' => $this->team->id,
+ 'private_key_id' => $this->privateKey->id,
+ ]);
+ $server->settings->update(['is_metrics_enabled' => true, 'is_reachable' => true, 'is_usable' => true]);
+
+ Livewire::test(ServerMetricsChart::class, ['server' => $server->fresh()])
+ ->call('loadData')
+ ->assertDispatched(
+ "dashboard-server-metrics-{$server->uuid}",
+ fn (string $name, array $params) => $params[0] == [
+ 'cpu' => [[1700000000000, 12.5]],
+ 'memory' => [[1700000000000, 40]],
+ ],
+ );
+
+ Process::assertRan(fn ($process) => str_contains($process->command, 'coolify-sentinel'));
+});