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

Commit

Permalink
Renamed HttpStatisticsLogger with MemoryStatisticsLogger (because it …
Browse files Browse the repository at this point in the history
…stores it in-memory)
  • Loading branch information
rennokki committed Aug 19, 2020
1 parent 850ebe5 commit 3123f25
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/websockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
|
*/

'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class,

/*
Expand Down
2 changes: 1 addition & 1 deletion docs/debugging/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ However, to disable it entirely and void any incoming statistic, you can uncomme
|
*/

// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, // use the `NullStatisticsLogger` instead
```

Expand Down
7 changes: 5 additions & 2 deletions src/Console/StartWebSocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class StartWebSocketServer extends Command
protected $signature = 'websockets:serve
{--host=0.0.0.0}
{--port=6001}
{--statistics-interval= : Overwrite the statistics interval set in the config.}
{--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.}
{--test : Prepare the server, but do not start it.}
';
Expand Down Expand Up @@ -110,15 +111,17 @@ protected function configureStatisticsLogger()
$browser = new Browser($this->loop, $connector);

$this->laravel->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class);
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class);

return new $class(
$this->laravel->make(ChannelManager::class),
$browser
);
});

$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function () {
$this->loop->addPeriodicTimer($this->option('statistics-interval') ?: config('websockets.statistics.interval_in_seconds'), function () {
$this->line('Saving statistics...');

StatisticsLogger::save();
});

Expand Down
4 changes: 2 additions & 2 deletions src/Facades/StatisticsLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Illuminate\Support\Facades\Facade;

/**
* @see \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger
* @mixin \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger
* @see \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger
* @mixin \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger
*/
class StatisticsLogger extends Facade
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function GuzzleHttp\Psr7\stream_for;
use Ratchet\ConnectionInterface;

class HttpStatisticsLogger implements StatisticsLogger
class MemoryStatisticsLogger implements StatisticsLogger
{
/**
* The list of stored statistics.
Expand Down
13 changes: 11 additions & 2 deletions tests/Statistics/Logger/FakeStatisticsLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Logger;

use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
use BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger;

class FakeStatisticsLogger extends HttpStatisticsLogger
class FakeStatisticsLogger extends MemoryStatisticsLogger
{
/**
* {@inheritdoc}
*/
public function save()
{
foreach ($this->statistics as $appId => $statistic) {
Expand All @@ -14,6 +17,12 @@ public function save()
}
}

/**
* Get app by id.
*
* @param mixed $appId
* @return array
*/
public function getForAppId($appId): array
{
$statistic = $this->findOrMakeStatisticForAppId($appId);
Expand Down

0 comments on commit 3123f25

Please sign in to comment.