clusev/app/Console/Commands/MockMetrics.php

33 lines
891 B
PHP

<?php
namespace App\Console\Commands;
use App\Events\MetricsTicked;
use Illuminate\Console\Command;
/**
* Dev placeholder for the real MetricsPoller (SSH). Broadcasts a rolling CPU
* value 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 metrics over Reverb (dev)';
public function handle(): int
{
$interval = max(1, (int) $this->option('interval'));
$cpu = 40;
$this->info("Broadcasting mock metrics every {$interval}s on channel 'metrics' …");
while (true) {
$cpu = max(2, min(98, $cpu + random_int(-12, 12)));
broadcast(new MetricsTicked($cpu));
$this->line('tick cpu='.$cpu);
sleep($interval);
}
}
}