diff --git a/web/app/Filament/Widgets/ServerDiskUsageStatistic.php b/web/app/Filament/Widgets/ServerDiskUsageStatistic.php index 5192a34..69253f0 100644 --- a/web/app/Filament/Widgets/ServerDiskUsageStatistic.php +++ b/web/app/Filament/Widgets/ServerDiskUsageStatistic.php @@ -109,7 +109,7 @@ class ServerDiskUsageStatistic extends ApexChartWidget 'stroke' => [ 'dashArray' => 10, ], - 'labels' => ['Free Space'], + 'labels' => ['Used Space'], 'colors' => ['#16a34a'], ]; diff --git a/web/app/Filament/Widgets/ServerMemoryStatistic.php b/web/app/Filament/Widgets/ServerMemoryStatistic.php index 66affe4..dad876c 100644 --- a/web/app/Filament/Widgets/ServerMemoryStatistic.php +++ b/web/app/Filament/Widgets/ServerMemoryStatistic.php @@ -18,7 +18,7 @@ class ServerMemoryStatistic extends ApexChartWidget * * @var string|null */ - protected static ?string $heading = 'Memory Usage'; + protected static ?string $heading = 'RAM Usage'; protected static ?int $sort = 2; @@ -37,7 +37,7 @@ class ServerMemoryStatistic extends ApexChartWidget $serverStatistic = new \App\Statistics\ServerStatistic(); $serverStats = $serverStatistic->getCurrentStats(); - return view('charts.order-status.footer', ['data' => $serverStats]); + return view('filament.widgets.server-memory-statistic', ['data' => $serverStats]); } @@ -50,9 +50,27 @@ class ServerMemoryStatistic extends ApexChartWidget $serverStatistic = new \App\Statistics\ServerStatistic(); $serverStats = $serverStatistic->getCurrentStats(); - $userPercentage = $serverStats['disk']['usedPercentage']; - $userPercentage = str_replace('%', '', $userPercentage); - $userPercentage = floatval($userPercentage); +// try { +// $memoryUsedPercentage = $serverStats['memory']['usedGb'] / $serverStats['memory']['totalGb'] * 100; +// } catch (\Exception $e) { +// $memoryUsedPercentage = 0; +// } +// $memoryUsedPercentage = round($memoryUsedPercentage, 0); + + $memoryUsedPercentage = 0; + $memoryFreePercentage = 0; + + try { + if ($serverStats['memory']['totalGb'] > 0) { + $memoryUsedPercentage = $serverStats['memory']['usedGb'] / $serverStats['memory']['totalGb'] * 100; + $memoryFreePercentage = 100 - $memoryUsedPercentage; + } + } catch (\Exception $e) { + // do nothing + } + + $memoryUsedPercentage = round($memoryUsedPercentage, 0); + $memoryFreePercentage = round($memoryFreePercentage, 0); return [ 'chart' => [ @@ -62,7 +80,7 @@ class ServerMemoryStatistic extends ApexChartWidget 'show' => false, ], ], - 'series' => [$userPercentage], + 'series' => [$memoryFreePercentage], 'plotOptions' => [ 'radialBar' => [ 'startAngle' => 0, @@ -109,7 +127,7 @@ class ServerMemoryStatistic extends ApexChartWidget 'stroke' => [ 'dashArray' => 10, ], - 'labels' => ['Free Space'], + 'labels' => ['Used RAM'], 'colors' => ['#16a34a'], ]; diff --git a/web/app/Providers/Filament/AdminPanelProvider.php b/web/app/Providers/Filament/AdminPanelProvider.php index 77a6064..ea28568 100644 --- a/web/app/Providers/Filament/AdminPanelProvider.php +++ b/web/app/Providers/Filament/AdminPanelProvider.php @@ -82,7 +82,8 @@ class AdminPanelProvider extends PanelProvider // ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets') ->widgets([ ServerDiskUsageStatistic::class, - ServerMemoryStatisticCount::class, + ServerMemoryStatistic::class, + // ServerMemoryStatisticCount::class, CustomersCount::class, Websites::class, // Widgets\AccountWidget::class, diff --git a/web/app/Statistics/ServerStatistic.php b/web/app/Statistics/ServerStatistic.php index 18ab50d..3298bfc 100644 --- a/web/app/Statistics/ServerStatistic.php +++ b/web/app/Statistics/ServerStatistic.php @@ -19,15 +19,19 @@ class ServerStatistic $freeMemoryExp = explode(' ', $freeMemoryExec); if (isset($freeMemoryExp[1])) { $memory['total'] = $this->getFormattedFileSize($freeMemoryExp[1] * 1024 * 1024, 2); + $memory['totalGb'] = $freeMemoryExp[1] * 1024 * 1024; } if (isset($freeMemoryExp[2])) { $memory['used'] = $this->getFormattedFileSize($freeMemoryExp[2] * 1024 * 1024, 2); + $memory['usedGb'] = $freeMemoryExp[2] * 1024 * 1024; } if (isset($freeMemoryExp[3])) { $memory['free'] = $this->getFormattedFileSize($freeMemoryExp[3] * 1024 * 1024, 2); + $memory['freeGb'] = $freeMemoryExp[3] * 1024 * 1024; } if (isset($freeMemoryExp[4])) { $memory['shared'] = $this->getFormattedFileSize($freeMemoryExp[4] * 1024 * 1024, 2); + $memory['sharedGb'] = $freeMemoryExp[4] * 1024 * 1024; } if (isset($freeMemoryExp[5])) { $memory['buffCache'] = $this->getFormattedFileSize($freeMemoryExp[5] * 1024 * 1024, 2); diff --git a/web/resources/views/filament/widgets/server-memory-statistic.blade.php b/web/resources/views/filament/widgets/server-memory-statistic.blade.php new file mode 100644 index 0000000..fedc5e1 --- /dev/null +++ b/web/resources/views/filament/widgets/server-memory-statistic.blade.php @@ -0,0 +1,23 @@ +