wip
This commit is contained in:
parent
6c96bb8edc
commit
fd2203c8bb
|
|
@ -42,10 +42,19 @@ return [
|
|||
*/
|
||||
'max_request_size_in_kb' => 250,
|
||||
|
||||
/*
|
||||
* This model will be used to store the statistics of the WebSocketsServer
|
||||
*/
|
||||
'statistics_model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
|
||||
'statistics' => [
|
||||
/*
|
||||
* This model will be used to store the statistics of the WebSocketsServer.
|
||||
* The only requirement is that the model should be or extend
|
||||
* `WebSocketsStatisticsEntry` provided by this package.
|
||||
*/
|
||||
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
|
||||
|
||||
/*
|
||||
* Here you can specify the interval in seconds at which statistics should be logged.
|
||||
*/
|
||||
'interval_in_seconds' => 60,
|
||||
],
|
||||
|
||||
/*
|
||||
* Define the optional SSL context for your WebSocket connections.
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class StartWebSocketServer extends Command
|
|||
return new HttpStatisticsLogger(app(ChannelManager::class), $browser);
|
||||
});
|
||||
|
||||
$this->loop->addPeriodicTimer(5, function() {
|
||||
$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function() {
|
||||
StatisticsLogger::save();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace BeyondCode\LaravelWebsockets\Statistics\Events;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
|
||||
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
|
@ -11,27 +12,30 @@ class StatisticsUpdated implements ShouldBroadcast
|
|||
{
|
||||
use SerializesModels;
|
||||
|
||||
protected $statisticModel;
|
||||
/** @var \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry */
|
||||
protected $webSocketsStatisticsEntry;
|
||||
|
||||
public function __construct($statisticModel)
|
||||
public function __construct(WebSocketsStatisticsEntry $webSocketsStatisticsEntry)
|
||||
{
|
||||
$this->statisticModel = $statisticModel;
|
||||
$this->webSocketsStatisticsEntry = $webSocketsStatisticsEntry;
|
||||
}
|
||||
|
||||
public function broadcastWith()
|
||||
{
|
||||
return [
|
||||
'time' => $this->statisticModel->created_at->timestamp,
|
||||
'app_id' => $this->statisticModel->appId,
|
||||
'peak_connection_count' => $this->statisticModel->peakConnectionCount,
|
||||
'websocket_message_count' => $this->statisticModel->webSocketMessageCount,
|
||||
'api_message_count' => $this->statisticModel->apiMessageCount,
|
||||
'time' => $this->webSocketsStatisticsEntry->created_at->timestamp,
|
||||
'app_id' => $this->webSocketsStatisticsEntry->appId,
|
||||
'peak_connection_count' => $this->webSocketsStatisticsEntry->peakConnectionCount,
|
||||
'websocket_message_count' => $this->webSocketsStatisticsEntry->webSocketMessageCount,
|
||||
'api_message_count' => $this->webSocketsStatisticsEntry->apiMessageCount,
|
||||
];
|
||||
}
|
||||
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel(str_after(DashboardLogger::LOG_CHANNEL_PREFIX . 'statistics', 'private-'));
|
||||
$channelName = str_after(DashboardLogger::LOG_CHANNEL_PREFIX . 'statistics', 'private-');
|
||||
|
||||
return new PrivateChannel($channelName);
|
||||
}
|
||||
|
||||
public function broadcastAs()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class WebSocketStatisticsEntriesController
|
|||
'api_message_count' => 'required|integer',
|
||||
]);
|
||||
|
||||
$webSocketsStatisticsEntryModelClass = config('websockets.statistics_model');
|
||||
$webSocketsStatisticsEntryModelClass = config('websockets.statistics.model');
|
||||
|
||||
$statisticModel = $webSocketsStatisticsEntryModelClass::create($validatedAttributes);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue