Skip to content

Commit

Permalink
add overview stats to console
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 committed Oct 18, 2024
1 parent 444fa7b commit a314fd8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Filament/App/Pages/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Filament\App\Widgets\ServerCpuChart;
use App\Filament\App\Widgets\ServerMemoryChart;
use App\Filament\App\Widgets\ServerNetworkChart;
use App\Filament\App\Widgets\ServerOverview;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Pages\Page;
Expand All @@ -27,6 +28,7 @@ public function getWidgetData(): array
public function getWidgets(): array
{
return [
ServerOverview::class,
ServerConsole::class,
ServerCpuChart::class,
ServerMemoryChart::class,
Expand Down
35 changes: 35 additions & 0 deletions app/Filament/App/Widgets/ServerOverview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Filament\App\Widgets;

use App\Models\Server;
use Carbon\CarbonInterface;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Str;

class ServerOverview extends StatsOverviewWidget
{
public ?Server $server = null;

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()),
];
}

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

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

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

0 comments on commit a314fd8

Please sign in to comment.