mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 22:14:45 +02:00

* add custom statblock * add custom datablock * Use real values, not placeholders * More Changes * remove unused var * Remove old code * Remove more * Updates * Add LineHeight Changing the font size cut off the j/g and _ * Fix invisible console selection Closes #874 * Add Missing to `offline` detection * Use helper * Update * Removals * Move to `SmallStatBlock`
76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Server\Widgets;
|
|
|
|
use App\Models\Server;
|
|
use Carbon\Carbon;
|
|
use Filament\Support\RawJs;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Illuminate\Support\Number;
|
|
|
|
class ServerCpuChart extends ChartWidget
|
|
{
|
|
protected static ?string $pollingInterval = '1s';
|
|
|
|
protected static ?string $maxHeight = '200px';
|
|
|
|
public ?Server $server = null;
|
|
|
|
protected function getData(): array
|
|
{
|
|
$cpu = collect(cache()->get("servers.{$this->server->id}.cpu_absolute"))
|
|
->slice(-10)
|
|
->map(fn ($value, $key) => [
|
|
'cpu' => Number::format($value, maxPrecision: 2),
|
|
'timestamp' => Carbon::createFromTimestamp($key, auth()->user()->timezone ?? 'UTC')->format('H:i:s'),
|
|
])
|
|
->all();
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'data' => array_column($cpu, 'cpu'),
|
|
'backgroundColor' => [
|
|
'rgba(96, 165, 250, 0.3)',
|
|
],
|
|
'tension' => '0.3',
|
|
'fill' => true,
|
|
],
|
|
],
|
|
'labels' => array_column($cpu, 'timestamp'),
|
|
'locale' => auth()->user()->language ?? 'en',
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'line';
|
|
}
|
|
|
|
protected function getOptions(): RawJs
|
|
{
|
|
return RawJs::make(<<<'JS'
|
|
{
|
|
scales: {
|
|
y: {
|
|
min: 0,
|
|
},
|
|
x: {
|
|
display: false,
|
|
}
|
|
},
|
|
plugins: {
|
|
legend: {
|
|
display: false,
|
|
}
|
|
}
|
|
}
|
|
JS);
|
|
}
|
|
|
|
public function getHeading(): string
|
|
{
|
|
return 'CPU';
|
|
}
|
|
}
|