Skip to content

Commit

Permalink
Combine status & uptime, add address on ServerOverview (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 authored Dec 1, 2024
1 parent 4fd1937 commit 355810c
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/Filament/Server/Widgets/ServerOverview.php
Original file line number Diff line number Diff line change
@@ -19,19 +19,22 @@ protected function getStats(): array
return [
Stat::make('Name', $this->server->name)
->description($this->server->description),
Stat::make('Status', Str::title($this->server->condition)),
Stat::make('Uptime', $this->uptime()),
Stat::make('Status', $this->status()),
Stat::make('Address', $this->server->allocation->address),
];
}

private function uptime(): string
private function status(): string
{
$status = Str::title($this->server->condition);
$uptime = collect(cache()->get("servers.{$this->server->id}.uptime"))->last() ?? 0;

if ($uptime === 0) {
return 'Offline';
return $status;
}

return now()->subMillis($uptime)->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, short: true, parts: 2);
$uptime = now()->subMillis($uptime)->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, short: true, parts: 2);

return "$status ($uptime)";
}
}
1 change: 1 addition & 0 deletions app/Models/Allocation.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
* @property \Carbon\Carbon|null $updated_at
* @property string $alias
* @property bool $has_alias
* @property string $address
* @property \App\Models\Server|null $server
* @property \App\Models\Node $node
*

0 comments on commit 355810c

Please sign in to comment.