Merge pull request #442 from beyondcode/feature/custom-http-stats-logger

[feature] Custom HttpStatisticsLogger instance
This commit is contained in:
rennokki 2020-08-13 12:18:48 +03:00 committed by GitHub
commit 79ef005468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -81,6 +81,12 @@ return [
*/ */
'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class, 'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
/**
* The Statistics Logger will, by default, handle the incoming statistics, store them
* and then release them into the database on each interval defined below.
*/
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger::class,
/* /*
* Here you can specify the interval in seconds at which statistics should be logged. * Here you can specify the interval in seconds at which statistics should be logged.
*/ */

View File

@ -9,7 +9,6 @@ use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger; use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory; use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver; use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface; use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Clue\React\Buzz\Browser; use Clue\React\Buzz\Browser;
@ -61,7 +60,9 @@ class StartWebSocketServer extends Command
$browser = new Browser($this->loop, $connector); $browser = new Browser($this->loop, $connector);
app()->singleton(StatisticsLoggerInterface::class, function () use ($browser) { app()->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
return new HttpStatisticsLogger(app(ChannelManager::class), $browser); $class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger::class);
return new $class(app(ChannelManager::class), $browser);
}); });
$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function () { $this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function () {