clusev/app/Console/Commands/MockMetrics.php

35 lines
997 B
PHP

<?php
namespace App\Console\Commands;
use App\Events\MetricsTicked;
use Illuminate\Console\Command;
/**
* Dev placeholder for the real MetricsPoller (SSH). Broadcasts rolling CPU+MEM
* values over Reverb so the dashboard chart moves live.
*/
class MockMetrics extends Command
{
protected $signature = 'clusev:mock-metrics {--interval=2 : Seconds between ticks}';
protected $description = 'Broadcast mock CPU+MEM metrics over Reverb (dev)';
public function handle(): int
{
$interval = max(1, (int) $this->option('interval'));
$cpu = 40;
$mem = 55;
$this->info("Broadcasting mock metrics every {$interval}s on channel 'metrics' …");
while (true) {
$cpu = max(2, min(98, $cpu + random_int(-12, 12)));
$mem = max(2, min(98, $mem + random_int(-6, 6)));
broadcast(new MetricsTicked($cpu, $mem));
$this->line("tick cpu={$cpu} mem={$mem}");
sleep($interval);
}
}
}