40 lines
975 B
PHP
40 lines
975 B
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use Illuminate\Broadcasting\Channel;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
/**
|
|
* A single CPU metric sample for a server, pushed to the browser over Reverb.
|
|
* Dev: emitted by `clusev:mock-metrics`. Later: by MetricsPoller (SSH).
|
|
*/
|
|
class MetricsTicked implements ShouldBroadcast
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public function __construct(
|
|
public int $cpu,
|
|
public string $server = 'web-01',
|
|
) {}
|
|
|
|
public function broadcastOn(): Channel
|
|
{
|
|
return new Channel('metrics');
|
|
}
|
|
|
|
public function broadcastAs(): string
|
|
{
|
|
return 'tick';
|
|
}
|
|
|
|
/** @return array<string,mixed> */
|
|
public function broadcastWith(): array
|
|
{
|
|
return ['cpu' => $this->cpu, 'server' => $this->server];
|
|
}
|
|
}
|