Added websockets:flush command
This commit is contained in:
parent
be9e21e518
commit
f04cce73d3
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace BeyondCode\LaravelWebSockets\Console\Commands;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Facades\StatisticsCollector;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FlushCollectedStatistics extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'websockets:flush';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $description = 'Flush the collected statistics.';
|
||||
|
||||
/**
|
||||
* Run the command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->comment('Flushing the collected WebSocket Statistics...');
|
||||
|
||||
StatisticsCollector::flush();
|
||||
|
||||
$this->line('Flush complete!');
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
namespace BeyondCode\LaravelWebSockets\Console\Commands;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Contracts\ChannelManager;
|
||||
use BeyondCode\LaravelWebSockets\Contracts\StatisticsCollector;
|
||||
use BeyondCode\LaravelWebSockets\Facades\StatisticsCollector as StatisticsCollectorFacade;
|
||||
use BeyondCode\LaravelWebSockets\Facades\WebSocketRouter;
|
||||
use BeyondCode\LaravelWebSockets\Server\Loggers\ConnectionLogger;
|
||||
|
|
@ -120,14 +119,6 @@ class StartServer extends Command
|
|||
*/
|
||||
protected function configureStatistics()
|
||||
{
|
||||
$this->laravel->singleton(StatisticsCollector::class, function () {
|
||||
$replicationMode = config('websockets.replication.mode', 'local');
|
||||
|
||||
$class = config("websockets.replication.modes.{$replicationMode}.collector");
|
||||
|
||||
return new $class;
|
||||
});
|
||||
|
||||
if (! $this->option('disable-statistics')) {
|
||||
$intervalInSeconds = $this->option('statistics-interval') ?: config('websockets.statistics.interval_in_seconds', 3600);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace BeyondCode\LaravelWebSockets;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Contracts\StatisticsCollector;
|
||||
use BeyondCode\LaravelWebSockets\Contracts\StatisticsStore;
|
||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
|
||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
|
||||
|
|
@ -65,6 +66,14 @@ class WebSocketsServiceProvider extends ServiceProvider
|
|||
|
||||
return new $class;
|
||||
});
|
||||
|
||||
$this->app->singleton(StatisticsCollector::class, function () {
|
||||
$replicationMode = config('websockets.replication.mode', 'local');
|
||||
|
||||
$class = config("websockets.replication.modes.{$replicationMode}.collector");
|
||||
|
||||
return new $class;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -91,6 +100,7 @@ class WebSocketsServiceProvider extends ServiceProvider
|
|||
Console\Commands\StartServer::class,
|
||||
Console\Commands\RestartServer::class,
|
||||
Console\Commands\CleanStatistics::class,
|
||||
Console\Commands\FlushCollectedStatistics::class,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -222,24 +222,15 @@ abstract class TestCase extends Orchestra
|
|||
}
|
||||
|
||||
/**
|
||||
* Register the statistics collectors that are
|
||||
* not resolved by the package service provider.
|
||||
* Register the statistics collectors.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerStatisticsCollectors()
|
||||
{
|
||||
$this->app->singleton(StatisticsCollector::class, function () {
|
||||
$mode = config('websockets.replication.mode', $this->replicationMode);
|
||||
|
||||
$class = config("websockets.replication.modes.{$mode}.collector");
|
||||
|
||||
return new $class;
|
||||
});
|
||||
|
||||
$this->statisticsCollector = $this->app->make(StatisticsCollector::class);
|
||||
|
||||
$this->statisticsCollector->flush();
|
||||
$this->artisan('websockets:flush');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue