Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 9938cf6

Browse files
committed
Moved the statistics logger to the replication driver
1 parent fd46b0c commit 9938cf6

File tree

4 files changed

+9
-55
lines changed

4 files changed

+9
-55
lines changed

config/websockets.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189

190190
'client' => \BeyondCode\LaravelWebSockets\PubSub\Drivers\LocalClient::class,
191191

192+
'statistics_logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
193+
192194
],
193195

194196
/*
@@ -210,6 +212,8 @@
210212

211213
'client' => \BeyondCode\LaravelWebSockets\PubSub\Drivers\RedisClient::class,
212214

215+
'statistics_logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger::class,
216+
213217
],
214218

215219
],
@@ -238,24 +242,6 @@
238242

239243
],
240244

241-
/*
242-
|--------------------------------------------------------------------------
243-
| Statistics Logger Handler
244-
|--------------------------------------------------------------------------
245-
|
246-
| The Statistics Logger will, by default, handle the incoming statistics,
247-
| store them into an array and then store them into the database
248-
| on each interval.
249-
|
250-
| You can opt-in to avoid any statistics storage by setting the logger
251-
| to the built-in NullLogger.
252-
|
253-
*/
254-
255-
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
256-
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class,
257-
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger::class,
258-
259245
/*
260246
|--------------------------------------------------------------------------
261247
| Statistics Interval Period

docs/debugging/dashboard.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,11 @@ protected function schedule(Schedule $schedule)
7171

7272
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.
7373

74-
However, to disable it entirely and void any incoming statistic, you can uncomment the following line in the config:
74+
However, to disable it entirely and void any incoming statistic, you can change the statistics logger to `NullStatisticsLogger` under your current replication driver.
7575

7676
```php
77-
/*
78-
|--------------------------------------------------------------------------
79-
| Statistics Logger Handler
80-
|--------------------------------------------------------------------------
81-
|
82-
| The Statistics Logger will, by default, handle the incoming statistics,
83-
| store them into an array and then store them into the database
84-
| on each interval.
85-
|
86-
| You can opt-in to avoid any statistics storage by setting the logger
87-
| to the built-in NullLogger.
88-
|
89-
*/
90-
9177
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
92-
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, // use the `NullStatisticsLogger` instead
78+
'statistics_logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, // use the `NullStatisticsLogger` instead
9379
```
9480

9581
## Custom Statistics Drivers

docs/horizontal-scaling/getting-started.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,3 @@ Now, when your app broadcasts the message, it will make sure the connection reac
3232
The available drivers for replication are:
3333

3434
- [Redis](redis)
35-
36-
## Configure the Statistics driver
37-
38-
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.
39-
40-
Unfortunately, you might end up with multiple rows when multiple servers run in parallel.
41-
42-
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:
43-
44-
```php
45-
'statistics' => [
46-
47-
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger::class,
48-
49-
...
50-
51-
],
52-
```
53-
54-
Check the `websockets.php` config file for more details.

src/Console/StartWebSocketServer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ public function handle()
9797
protected function configureStatisticsLogger()
9898
{
9999
$this->laravel->singleton(StatisticsLoggerInterface::class, function () {
100-
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class);
100+
$replicationDriver = config('websockets.replication.driver', 'local');
101+
102+
$class = config("websockets.replication.{$replicationDriver}.statistics_logger", \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class);
101103

102104
return new $class(
103105
$this->laravel->make(ChannelManager::class),

0 commit comments

Comments
 (0)