From 6b11fa26ce8b0083e3aa9bc2ae070e042d3261e9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 17 Aug 2022 10:55:01 +0000 Subject: [PATCH] rename and remove unused param --- app/controllers/shared/api.php | 21 ++++++++++++--------- src/Appwrite/Usage/Stats.php | 29 ++++++++++------------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 6631c55c51..f28a223e64 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -139,13 +139,10 @@ App::init() $usage ->setParam('projectId', $project->getId()) - ->setParam('httpRequest', 1) - ->setParam('httpUrl', $request->getHostname() . $request->getURI()) + ->setParam('project.{scope}.network.requests', 1) ->setParam('httpMethod', $request->getMethod()) - ->setParam('httpPath', $route->getPath()) - ->setParam('networkRequestSize', 0) - ->setParam('networkResponseSize', 0) - ->setParam('storage', 0); + ->setParam('project.{scope}.network.inbound', 0) + ->setParam('project.{scope}.network.outbound', 0); $deletes->setProject($project); $database->setProject($project); @@ -356,9 +353,15 @@ App::shutdown() } } + $fileSize = 0; + $file = $request->getFiles('file'); + if(!empty($file)) { + $fileSize = (\is_array($file['size']) && isset($file['size'][0])) ? $file['size'][0] : $file['size']; + } + $usage - ->setParam('networkRequestSize', $request->getSize() + $usage->getParam('storage')) - ->setParam('networkResponseSize', $response->getSize()) - ->submit(); + ->setParam('project.{scope}.network.inbound', $request->getSize() + $fileSize) + ->setParam('project.{scope}.network.outbound', $response->getSize()) + ->submit(); } }); diff --git a/src/Appwrite/Usage/Stats.php b/src/Appwrite/Usage/Stats.php index f6a9b29156..e01027ce54 100644 --- a/src/Appwrite/Usage/Stats.php +++ b/src/Appwrite/Usage/Stats.php @@ -80,26 +80,22 @@ class Stats public function submit(): void { $projectId = $this->params['projectId'] ?? ''; - - $storage = $this->params['storage'] ?? 0; - - $networkRequestSize = $this->params['networkRequestSize'] ?? 0; - $networkResponseSize = $this->params['networkResponseSize'] ?? 0; - - $httpMethod = $this->params['httpMethod'] ?? ''; - $httpRequest = $this->params['httpRequest'] ?? 0; - $tags = ",projectId={$projectId},version=" . App::getEnv('_APP_VERSION', 'UNKNOWN'); - + // the global namespace is prepended to every key (optional) $this->statsd->setNamespace($this->namespace); - + + $httpRequest = $this->params['project.{scope}.network.requests'] ?? 0; + $httpMethod = $this->params['httpMethod'] ?? ''; if ($httpRequest >= 1) { $this->statsd->increment('project.{scope}.network.requests' . $tags . ',method=' . \strtolower($httpMethod)); } - $this->statsd->count('project.{scope}.network.inbound' . $tags, $networkRequestSize); - $this->statsd->count('project.{scope}.network.outbound' . $tags, $networkResponseSize); - $this->statsd->count('project.{scope}.network.bandwidth' . $tags, $networkRequestSize + $networkResponseSize); + + $inbound = $this->params['networkRequestSize'] ?? 0; + $outbound = $this->params['networkResponseSize'] ?? 0; + $this->statsd->count('project.{scope}.network.inbound' . $tags, $inbound); + $this->statsd->count('project.{scope}.network.outbound' . $tags, $outbound); + $this->statsd->count('project.{scope}.network.bandwidth' . $tags, $inbound + $outbound); $usersMetrics = [ 'users.{scope}.requests.create', @@ -171,11 +167,6 @@ class Stats } } - if ($storage >= 1) { - $storageTags = $tags . ",bucketId=" . ($this->params['bucketId'] ?? ''); - $this->statsd->count('storage.all' . $storageTags, $storage); - } - $functionId = $this->params['functionId'] ?? ''; $functionExecution = $this->params['executions.{scope}.compute'] ?? 0; $functionExecutionTime = ($this->params['executionTime'] ?? 0) * 1000; // ms