diff --git a/web/app/Filament/Resources/HostingSubscriptionResource.php b/web/app/Filament/Resources/HostingSubscriptionResource.php index f99bcd8..7408681 100644 --- a/web/app/Filament/Resources/HostingSubscriptionResource.php +++ b/web/app/Filament/Resources/HostingSubscriptionResource.php @@ -116,6 +116,7 @@ class HostingSubscriptionResource extends Resource { return $table ->columns([ + Tables\Columns\TextColumn::make('domain') ->searchable() ->sortable(), diff --git a/web/app/Filament/Widgets/CustomersCount.php b/web/app/Filament/Widgets/CustomersCount.php index 9ddd457..721e594 100644 --- a/web/app/Filament/Widgets/CustomersCount.php +++ b/web/app/Filament/Widgets/CustomersCount.php @@ -12,6 +12,10 @@ class CustomersCount extends BaseWidget protected static bool $isLazy = false; protected function getStats(): array { + + $serverStatistic = new \App\Statistics\ServerStatistic(); + $serverStatistic->getCurrentStats(); + $customersCount = Customer::count(); $websiteCount = Website::count(); diff --git a/web/app/Statistics/ServerStatistic.php b/web/app/Statistics/ServerStatistic.php new file mode 100644 index 0000000..c49f888 --- /dev/null +++ b/web/app/Statistics/ServerStatistic.php @@ -0,0 +1,67 @@ + 0, + 'used' => 0, + 'free' => 0, + 'shared' => 0, + 'buffCache' => 0, + 'available' => 0 + ]; + + $freeMemoryExec = shell_exec('free -m | grep Mem | awk \'{print $1 " " $2 " " $3 " " $4 " " $6 " " $7}\''); + $freeMemoryExp = explode(' ', $freeMemoryExec); + if (isset($freeMemoryExp[1])) { + $memory['total'] = $this->getFormattedFileSize($freeMemoryExp[1] * 1024 * 1024, 2); + } + if (isset($freeMemoryExp[2])) { + $memory['used'] = $this->getFormattedFileSize($freeMemoryExp[2] * 1024 * 1024, 2); + } + if (isset($freeMemoryExp[3])) { + $memory['free'] = $this->getFormattedFileSize($freeMemoryExp[3] * 1024 * 1024, 2); + } + if (isset($freeMemoryExp[4])) { + $memory['shared'] = $this->getFormattedFileSize($freeMemoryExp[4] * 1024 * 1024, 2); + } + if (isset($freeMemoryExp[5])) { + $memory['buffCache'] = $this->getFormattedFileSize($freeMemoryExp[5] * 1024 * 1024, 2); + } + if (isset($freeMemoryExp[6])) { + $memory['available'] = $this->getFormattedFileSize($freeMemoryExp[6] * 1024 * 1024, 2); + } + + + + + return $memory; + + } + + + + public function getFormattedFileSize($size, $precision) { + switch (true) + { + case ($size/1024 < 1): + return $size.'B'; + case ($size/pow(1024, 2) < 1): + return round($size/1024, $precision).'KB'; + case ($size/pow(1024, 3) < 1): + return round($size/pow(1024, 2), $precision).'MB'; + case ($size/pow(1024, 4) < 1): + return round($size/pow(1024, 3), $precision).'GB'; + case ($size/pow(1024, 5) < 1): + return round($size/pow(1024, 4), $precision).'TB'; + default: + return 'Error: invalid input or file is too large.'; + } + } + + +}