diff --git a/config/websockets.php b/config/websockets.php index 65d91ce..b369922 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -189,6 +189,8 @@ return [ 'client' => \BeyondCode\LaravelWebSockets\PubSub\Drivers\LocalClient::class, + 'statistics_logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class, + ], /* @@ -210,6 +212,8 @@ return [ 'client' => \BeyondCode\LaravelWebSockets\PubSub\Drivers\RedisClient::class, + 'statistics_logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger::class, + ], ], @@ -238,24 +242,6 @@ return [ ], - /* - |-------------------------------------------------------------------------- - | Statistics Logger Handler - |-------------------------------------------------------------------------- - | - | The Statistics Logger will, by default, handle the incoming statistics, - | store them into an array and then store them into the database - | on each interval. - | - | You can opt-in to avoid any statistics storage by setting the logger - | to the built-in NullLogger. - | - */ - - 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class, - // 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, - // 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger::class, - /* |-------------------------------------------------------------------------- | Statistics Interval Period diff --git a/docs/debugging/dashboard.md b/docs/debugging/dashboard.md index 57f50e6..a108a8c 100644 --- a/docs/debugging/dashboard.md +++ b/docs/debugging/dashboard.md @@ -71,25 +71,11 @@ protected function schedule(Schedule $schedule) Each app contains an `enable_statistics` that defines wether that app generates statistics or not. The statistics are being stored for the `interval_in_seconds` seconds and then they are inserted in the database. -However, to disable it entirely and void any incoming statistic, you can uncomment the following line in the config: +However, to disable it entirely and void any incoming statistic, you can change the statistics logger to `NullStatisticsLogger` under your current replication driver. ```php -/* -|-------------------------------------------------------------------------- -| Statistics Logger Handler -|-------------------------------------------------------------------------- -| -| The Statistics Logger will, by default, handle the incoming statistics, -| store them into an array and then store them into the database -| on each interval. -| -| You can opt-in to avoid any statistics storage by setting the logger -| to the built-in NullLogger. -| -*/ - // 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class, -'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, // use the `NullStatisticsLogger` instead +'statistics_logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, // use the `NullStatisticsLogger` instead ``` ## Custom Statistics Drivers diff --git a/docs/horizontal-scaling/getting-started.md b/docs/horizontal-scaling/getting-started.md index 3408fff..fffd7fa 100644 --- a/docs/horizontal-scaling/getting-started.md +++ b/docs/horizontal-scaling/getting-started.md @@ -32,23 +32,3 @@ Now, when your app broadcasts the message, it will make sure the connection reac The available drivers for replication are: - [Redis](redis) - -## Configure the Statistics driver - -If you work with multi-node environments, beside replication, you shall take a look at the statistics logger. Each time your user connects, disconnects or send a message, you can track the statistics. However, these are centralized in one place before they are dumped in the database. - -Unfortunately, you might end up with multiple rows when multiple servers run in parallel. - -To fix this, just change the `statistics.logger` class with a logger that is able to centralize the statistics in one place. For example, you might want to store them into a Redis instance: - -```php -'statistics' => [ - - 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger::class, - - ... - -], -``` - -Check the `websockets.php` config file for more details. diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index fcf0737..0707e05 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -97,7 +97,9 @@ class StartWebSocketServer extends Command protected function configureStatisticsLogger() { $this->laravel->singleton(StatisticsLoggerInterface::class, function () { - $class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class); + $replicationDriver = config('websockets.replication.driver', 'local'); + + $class = config("websockets.replication.{$replicationDriver}.statistics_logger", \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class); return new $class( $this->laravel->make(ChannelManager::class),