This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +49
-20
lines changed
Expand file tree Collapse file tree 4 files changed +49
-20
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BeyondCode \LaravelWebSockets \Console \Commands ;
4+
5+ use BeyondCode \LaravelWebSockets \Facades \StatisticsCollector ;
6+ use Illuminate \Console \Command ;
7+
8+ class FlushCollectedStatistics extends Command
9+ {
10+ /**
11+ * The name and signature of the console command.
12+ *
13+ * @var string
14+ */
15+ protected $ signature = 'websockets:flush ' ;
16+
17+ /**
18+ * The console command description.
19+ *
20+ * @var string|null
21+ */
22+ protected $ description = 'Flush the collected statistics. ' ;
23+
24+ /**
25+ * Run the command.
26+ *
27+ * @return void
28+ */
29+ public function handle ()
30+ {
31+ $ this ->comment ('Flushing the collected WebSocket Statistics... ' );
32+
33+ StatisticsCollector::flush ();
34+
35+ $ this ->line ('Flush complete! ' );
36+ }
37+ }
Original file line number Diff line number Diff line change 33namespace BeyondCode \LaravelWebSockets \Console \Commands ;
44
55use BeyondCode \LaravelWebSockets \Contracts \ChannelManager ;
6- use BeyondCode \LaravelWebSockets \Contracts \StatisticsCollector ;
76use BeyondCode \LaravelWebSockets \Facades \StatisticsCollector as StatisticsCollectorFacade ;
87use BeyondCode \LaravelWebSockets \Facades \WebSocketRouter ;
98use BeyondCode \LaravelWebSockets \Server \Loggers \ConnectionLogger ;
@@ -120,14 +119,6 @@ protected function configureManagers()
120119 */
121120 protected function configureStatistics ()
122121 {
123- $ this ->laravel ->singleton (StatisticsCollector::class, function () {
124- $ replicationMode = config ('websockets.replication.mode ' , 'local ' );
125-
126- $ class = config ("websockets.replication.modes. {$ replicationMode }.collector " );
127-
128- return new $ class ;
129- });
130-
131122 if (! $ this ->option ('disable-statistics ' )) {
132123 $ intervalInSeconds = $ this ->option ('statistics-interval ' ) ?: config ('websockets.statistics.interval_in_seconds ' , 3600 );
133124
Original file line number Diff line number Diff line change 22
33namespace BeyondCode \LaravelWebSockets ;
44
5+ use BeyondCode \LaravelWebSockets \Contracts \StatisticsCollector ;
56use BeyondCode \LaravelWebSockets \Contracts \StatisticsStore ;
67use BeyondCode \LaravelWebSockets \Dashboard \Http \Controllers \AuthenticateDashboard ;
78use BeyondCode \LaravelWebSockets \Dashboard \Http \Controllers \SendMessage ;
@@ -65,6 +66,14 @@ protected function registerStatistics()
6566
6667 return new $ class ;
6768 });
69+
70+ $ this ->app ->singleton (StatisticsCollector::class, function () {
71+ $ replicationMode = config ('websockets.replication.mode ' , 'local ' );
72+
73+ $ class = config ("websockets.replication.modes. {$ replicationMode }.collector " );
74+
75+ return new $ class ;
76+ });
6877 }
6978
7079 /**
@@ -91,6 +100,7 @@ protected function registerCommands()
91100 Console \Commands \StartServer::class,
92101 Console \Commands \RestartServer::class,
93102 Console \Commands \CleanStatistics::class,
103+ Console \Commands \FlushCollectedStatistics::class,
94104 ]);
95105 }
96106
Original file line number Diff line number Diff line change @@ -222,24 +222,15 @@ protected function registerManagers()
222222 }
223223
224224 /**
225- * Register the statistics collectors that are
226- * not resolved by the package service provider.
225+ * Register the statistics collectors.
227226 *
228227 * @return void
229228 */
230229 protected function registerStatisticsCollectors ()
231230 {
232- $ this ->app ->singleton (StatisticsCollector::class, function () {
233- $ mode = config ('websockets.replication.mode ' , $ this ->replicationMode );
234-
235- $ class = config ("websockets.replication.modes. {$ mode }.collector " );
236-
237- return new $ class ;
238- });
239-
240231 $ this ->statisticsCollector = $ this ->app ->make (StatisticsCollector::class);
241232
242- $ this ->statisticsCollector -> flush ( );
233+ $ this ->artisan ( ' websockets:flush ' );
243234 }
244235
245236 /**
You can’t perform that action at this time.
0 commit comments