Combine status & uptime, add address on ServerOverview (#739)

This commit is contained in:
Boy132 2024-12-01 18:12:28 +01:00 committed by GitHub
parent 4fd1937c54
commit 355810c549
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -19,19 +19,22 @@ class ServerOverview extends StatsOverviewWidget
return [ return [
Stat::make('Name', $this->server->name) Stat::make('Name', $this->server->name)
->description($this->server->description), ->description($this->server->description),
Stat::make('Status', Str::title($this->server->condition)), Stat::make('Status', $this->status()),
Stat::make('Uptime', $this->uptime()), 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; $uptime = collect(cache()->get("servers.{$this->server->id}.uptime"))->last() ?? 0;
if ($uptime === 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)";
} }
} }

View File

@ -20,6 +20,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property \Carbon\Carbon|null $updated_at * @property \Carbon\Carbon|null $updated_at
* @property string $alias * @property string $alias
* @property bool $has_alias * @property bool $has_alias
* @property string $address
* @property \App\Models\Server|null $server * @property \App\Models\Server|null $server
* @property \App\Models\Node $node * @property \App\Models\Node $node
* *