Files
vito/app/Console/Commands/GetMetricsCommand.php
Saeed Vaziry 131b828807 Plugins base (#613)
* wip

* wip

* cleanup

* notification channels

* phpstan

* services

* remove server types

* refactoring

* refactoring
2025-06-14 14:35:18 +02:00

35 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Enums\ServerStatus;
use App\Models\Server;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder;
class GetMetricsCommand extends Command
{
protected $signature = 'metrics:get';
protected $description = 'Get server metrics';
public function handle(): void
{
$checkedMetrics = 0;
Server::query()
->where('status', ServerStatus::READY)
->whereHas('services', function (Builder $query): void {
$query->where('type', 'monitoring')
->where('name', 'remote-monitor');
})->chunk(10, function ($servers) use (&$checkedMetrics): void {
/** @var Server $server */
foreach ($servers as $server) {
$info = $server->os()->resourceInfo();
$server->metrics()->create(array_merge($info, ['server_id' => $server->id]));
$checkedMetrics++;
}
});
$this->info("Checked $checkedMetrics metrics");
}
}