VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\HostingNode;
|
|
use App\Services\Hosting\NodeCapacityService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class RecalculateHostingNodeCapacityCommand extends Command
|
|
{
|
|
protected $signature = 'hosting:recalculate-node-capacity {--node=} {--shared-only}';
|
|
|
|
protected $description = 'Recalculate logical capacity, allocated disk, and load for hosting nodes.';
|
|
|
|
public function handle(NodeCapacityService $capacityService): int
|
|
{
|
|
$nodes = HostingNode::query()
|
|
->when($this->option('node'), fn ($query, $nodeId) => $query->where('id', $nodeId))
|
|
->when($this->option('shared-only'), fn ($query) => $query->where('type', HostingNode::TYPE_SHARED))
|
|
->get();
|
|
|
|
foreach ($nodes as $node) {
|
|
$node = $capacityService->refreshNodeResourceTotals($node);
|
|
$capacityService->checkNode($node);
|
|
|
|
$this->line(sprintf(
|
|
'%s: accounts=%d allocated=%dGB used=%dGB logical=%.2fGB load=%.2f%%',
|
|
$node->name,
|
|
$node->current_accounts,
|
|
$node->allocated_disk_gb,
|
|
$node->used_disk_gb,
|
|
$node->logicalCapacityGb(),
|
|
(float) $node->current_load_percent
|
|
));
|
|
}
|
|
|
|
$this->info("Recalculated capacity for {$nodes->count()} node(s).");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|