From 9c41cf32a21d9decc5df54c77f30c1e4260e9861 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 8 Dec 2020 16:52:55 +0200 Subject: [PATCH] Collect metrics only if statistics are enabled. --- src/API/TriggerEvent.php | 4 +++- src/Server/WebSocketHandler.php | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/API/TriggerEvent.php b/src/API/TriggerEvent.php index 5bb6738..7a3d986 100644 --- a/src/API/TriggerEvent.php +++ b/src/API/TriggerEvent.php @@ -49,7 +49,9 @@ class TriggerEvent extends Controller $request->appId, $request->socket_id, $channelName, (object) $payload ); - StatisticsCollector::apiMessage($request->appId); + if ($this->app->statisticsEnabled) { + StatisticsCollector::apiMessage($request->appId); + } DashboardLogger::log($request->appId, DashboardLogger::TYPE_API_MESSAGE, [ 'event' => $request->name, diff --git a/src/Server/WebSocketHandler.php b/src/Server/WebSocketHandler.php index 8bec389..855532d 100644 --- a/src/Server/WebSocketHandler.php +++ b/src/Server/WebSocketHandler.php @@ -56,7 +56,9 @@ class WebSocketHandler implements MessageComponentInterface /** @var \GuzzleHttp\Psr7\Request $request */ $request = $connection->httpRequest; - StatisticsCollector::connection($connection->app->id); + if ($connection->app->statisticsEnabled) { + StatisticsCollector::connection($connection->app->id); + } $this->channelManager->subscribeToApp($connection->app->id); @@ -88,7 +90,9 @@ class WebSocketHandler implements MessageComponentInterface $message, $connection, $this->channelManager )->respond(); - StatisticsCollector::webSocketMessage($connection->app->id); + if ($connection->app->statisticsEnabled) { + StatisticsCollector::webSocketMessage($connection->app->id); + } WebSocketMessageReceived::dispatch( $connection->app->id, @@ -109,7 +113,9 @@ class WebSocketHandler implements MessageComponentInterface ->unsubscribeFromAllChannels($connection) ->then(function (bool $unsubscribed) use ($connection) { if (isset($connection->app)) { - StatisticsCollector::disconnection($connection->app->id); + if ($connection->app->statisticsEnabled) { + StatisticsCollector::disconnection($connection->app->id); + } $this->channelManager->unsubscribeFromApp($connection->app->id);