This commit is contained in:
Bozhidar Slaveykov 2024-04-04 22:52:40 +03:00
parent bdd9aeec90
commit a4685b4c9b
4 changed files with 15 additions and 19 deletions

View file

@ -50,23 +50,15 @@ class ServerMemoryStatistic extends ApexChartWidget
$serverStatistic = new \App\Statistics\ServerStatistic();
$serverStats = $serverStatistic->getCurrentStats();
// 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
$totalMemory = $serverStats['memory']['totalGb'];
$availableMemory = $serverStats['memory']['availableGb'];
if ($totalMemory > 0) {
$memoryUsedPercentage = ($totalMemory - $availableMemory) / $totalMemory * 100;
$memoryFreePercentage = 100 - $memoryUsedPercentage;
}
$memoryUsedPercentage = round($memoryUsedPercentage, 0);
@ -80,7 +72,7 @@ class ServerMemoryStatistic extends ApexChartWidget
'show' => false,
],
],
'series' => [$memoryFreePercentage],
'series' => [$memoryUsedPercentage],
'plotOptions' => [
'radialBar' => [
'startAngle' => 0,

View file

@ -83,7 +83,7 @@ class AdminPanelProvider extends PanelProvider
->widgets([
ServerDiskUsageStatistic::class,
ServerMemoryStatistic::class,
// ServerMemoryStatisticCount::class,
ServerMemoryStatisticCount::class,
CustomersCount::class,
Websites::class,
// Widgets\AccountWidget::class,

View file

@ -2,6 +2,8 @@
namespace App\Statistics;
use Illuminate\Support\Facades\Cache;
class ServerStatistic
{
public function getCurrentStats()
@ -15,8 +17,9 @@ class ServerStatistic
'available' => 0
];
$freeMemoryExec = shell_exec('free -m | grep Mem | awk \'{print $1 " " $2 " " $3 " " $4 " " $6 " " $7}\'');
$freeMemoryExec = shell_exec('free -m | grep Mem | awk \'{print $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $7}\'');
$freeMemoryExp = explode(' ', $freeMemoryExec);
if (isset($freeMemoryExp[1])) {
$memory['total'] = $this->getFormattedFileSize($freeMemoryExp[1] * 1024 * 1024, 2);
$memory['totalGb'] = $freeMemoryExp[1] * 1024 * 1024;
@ -38,6 +41,7 @@ class ServerStatistic
}
if (isset($freeMemoryExp[6])) {
$memory['available'] = $this->getFormattedFileSize($freeMemoryExp[6] * 1024 * 1024, 2);
$memory['availableGb'] = $freeMemoryExp[6] * 1024 * 1024;
}
$diskMemoryExec = shell_exec('df -h | grep /dev/sda1 | awk \'{print $2 " " $3 " " $4 " " $5 " " $6}\'');

View file

@ -16,8 +16,8 @@
<div>
<h1>
Free Memory
Available Memory
</h1>
<div class="text-3xl">{{ $data['memory']['free'] }}</div>
<div class="text-3xl">{{ $data['memory']['available'] }}</div>
</div>
</div>