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 3
3
namespace BeyondCode \LaravelWebSockets \Console \Commands ;
4
4
5
5
use BeyondCode \LaravelWebSockets \Contracts \ChannelManager ;
6
- use BeyondCode \LaravelWebSockets \Contracts \StatisticsCollector ;
7
6
use BeyondCode \LaravelWebSockets \Facades \StatisticsCollector as StatisticsCollectorFacade ;
8
7
use BeyondCode \LaravelWebSockets \Facades \WebSocketRouter ;
9
8
use BeyondCode \LaravelWebSockets \Server \Loggers \ConnectionLogger ;
@@ -120,14 +119,6 @@ protected function configureManagers()
120
119
*/
121
120
protected function configureStatistics ()
122
121
{
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
-
131
122
if (! $ this ->option ('disable-statistics ' )) {
132
123
$ intervalInSeconds = $ this ->option ('statistics-interval ' ) ?: config ('websockets.statistics.interval_in_seconds ' , 3600 );
133
124
Original file line number Diff line number Diff line change 2
2
3
3
namespace BeyondCode \LaravelWebSockets ;
4
4
5
+ use BeyondCode \LaravelWebSockets \Contracts \StatisticsCollector ;
5
6
use BeyondCode \LaravelWebSockets \Contracts \StatisticsStore ;
6
7
use BeyondCode \LaravelWebSockets \Dashboard \Http \Controllers \AuthenticateDashboard ;
7
8
use BeyondCode \LaravelWebSockets \Dashboard \Http \Controllers \SendMessage ;
@@ -65,6 +66,14 @@ protected function registerStatistics()
65
66
66
67
return new $ class ;
67
68
});
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
+ });
68
77
}
69
78
70
79
/**
@@ -91,6 +100,7 @@ protected function registerCommands()
91
100
Console \Commands \StartServer::class,
92
101
Console \Commands \RestartServer::class,
93
102
Console \Commands \CleanStatistics::class,
103
+ Console \Commands \FlushCollectedStatistics::class,
94
104
]);
95
105
}
96
106
Original file line number Diff line number Diff line change @@ -222,24 +222,15 @@ protected function registerManagers()
222
222
}
223
223
224
224
/**
225
- * Register the statistics collectors that are
226
- * not resolved by the package service provider.
225
+ * Register the statistics collectors.
227
226
*
228
227
* @return void
229
228
*/
230
229
protected function registerStatisticsCollectors ()
231
230
{
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
-
240
231
$ this ->statisticsCollector = $ this ->app ->make (StatisticsCollector::class);
241
232
242
- $ this ->statisticsCollector -> flush ( );
233
+ $ this ->artisan ( ' websockets:flush ' );
243
234
}
244
235
245
236
/**
You can’t perform that action at this time.
0 commit comments