From 4bab152b3d5a5b61378388932df2c2918f48c78e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 15 Aug 2021 17:24:49 +0545 Subject: [PATCH] initial db metrics collection --- src/Appwrite/Stats/Stats.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Stats/Stats.php b/src/Appwrite/Stats/Stats.php index 9625d1c201..2f85be805c 100644 --- a/src/Appwrite/Stats/Stats.php +++ b/src/Appwrite/Stats/Stats.php @@ -87,7 +87,6 @@ class Stats $networkResponseSize = $this->params['networkResponseSize'] ?? 0; $httpMethod = $this->params['httpMethod'] ?? ''; - $httpPath = $this->params['httpPath'] ?? ''; $httpRequest = $this->params['httpRequest'] ?? 0; $functionId = $this->params['functionId'] ?? ''; @@ -101,7 +100,7 @@ class Stats $this->statsd->setNamespace($this->namespace); if ($httpRequest >= 1) { - $this->statsd->increment('requests.all' . $tags . ',method=' . \strtolower($httpMethod) . ',path=' . str_replace(':', '*', $httpPath)); + $this->statsd->increment('requests.all' . $tags . ',method=' . \strtolower($httpMethod)); } if ($functionExecution >= 1) { @@ -113,6 +112,25 @@ class Stats $this->statsd->count('network.outbound' . $tags, $networkResponseSize); $this->statsd->count('network.all' . $tags, $networkRequestSize + $networkResponseSize); + $dbMetrics = [ + 'database.collections.create', + 'database.collections.read', + 'database.collections.update', + 'database.collections.delete', + 'database.documents.create', + 'database.documents.read', + 'database.documents.update', + 'database.documents.delete', + ]; + + foreach ($dbMetrics as $metric) { + $value = $this->params[$metric] ?? 0; + if ($value >= 1) { + $dbTags = ",project={$projectId},collectionId=" . ($this->params['collectionId'] ?? ''); + $this->statsd->increment($metric . $dbTags); + } + } + if ($storage >= 1) { $this->statsd->count('storage.all' . $tags, $storage); }