This commit is contained in:
Bozhidar Slaveykov 2024-04-04 20:17:27 +03:00
parent fd7c9285d2
commit f6f92bd5de
3 changed files with 72 additions and 0 deletions

View file

@ -116,6 +116,7 @@ class HostingSubscriptionResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('domain')
->searchable()
->sortable(),

View file

@ -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();

View file

@ -0,0 +1,67 @@
<?php
namespace App\Statistics;
class ServerStatistic
{
public function getCurrentStats()
{
$memory =[
'total' => 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.';
}
}
}