diff --git a/app/init/constants.php b/app/init/constants.php index afed64f798..3b81785690 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -271,6 +271,8 @@ const METRIC_SITES_ID_REQUESTS = 'sites.{siteInternalId}.requests'; const METRIC_SITES_ID_INBOUND = 'sites.{siteInternalId}.inbound'; const METRIC_SITES_ID_OUTBOUND = 'sites.{siteInternalId}.outbound'; const METRIC_AVATARS_SCREENSHOTS_GENERATED = 'avatars.screenshotsGenerated'; +const METRIC_FUNCTIONS_RUNTIME = 'functions.runtimes.{runtime}'; +const METRIC_SITES_FRAMEWORK = 'sites.frameworks.{framework}'; // Resource types const RESOURCE_TYPE_PROJECTS = 'projects'; diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index 5ec306c5bb..1ef348091a 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -335,7 +335,11 @@ class StatsResources extends Action $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_DEPLOYMENTS), $deployments); $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_FUNCTIONS, METRIC_RESOURCE_TYPE_BUILDS), $deployments); - $this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $region) { + + // Count runtimes + $runtimes = []; + + $this->foreachDocument($dbForProject, 'functions', [], function (Document $function) use ($dbForProject, $region, &$runtimes) { $functionDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ Query::equal('resourceInternalId', [$function->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_FUNCTIONS]), @@ -364,7 +368,19 @@ class StatsResources extends Action }); $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS,$function->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $functionBuildsStorage); + + // Runtimes count + $runtime = $function->getAttribute('runtime'); + if (!empty($runtime)) { + $runtimes[$runtime] = ($runtimes[$runtime] ?? 0) + 1; + } }); + + // Write runtimes counts + foreach ($runtimes as $runtime => $count) { + $this->createStatsDocuments($region, str_replace('{runtime}', $runtime, METRIC_FUNCTIONS_RUNTIME), $count); + } + } protected function countForSites(Database $dbForProject, string $region) @@ -385,7 +401,10 @@ class StatsResources extends Action $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_DEPLOYMENTS), $deployments); $this->createStatsDocuments($region, str_replace("{resourceType}", RESOURCE_TYPE_SITES, METRIC_RESOURCE_TYPE_BUILDS), $deployments); - $this->foreachDocument($dbForProject, 'sites', [], function (Document $site) use ($dbForProject, $region) { + // Count frameworks + $frameworks = []; + + $this->foreachDocument($dbForProject, 'sites', [], function (Document $site) use ($dbForProject, $region, &$frameworks) { $siteDeploymentsStorage = $dbForProject->sum('deployments', 'sourceSize', [ Query::equal('resourceInternalId', [$site->getSequence()]), Query::equal('resourceType', [RESOURCE_TYPE_SITES]), @@ -410,7 +429,18 @@ class StatsResources extends Action ]); $this->createStatsDocuments($region, str_replace(['{resourceType}','{resourceInternalId}'], [RESOURCE_TYPE_SITES,$site->getSequence()], METRIC_RESOURCE_TYPE_ID_BUILDS_STORAGE), $siteBuildsStorage); + + // Frameworks count + $framework = $site->getAttribute('framework'); + if (!empty($framework)) { + $frameworks[$framework] = ($frameworks[$framework] ?? 0) + 1; + } }); + + // Write frameworks counts + foreach ($frameworks as $framework => $count) { + $this->createStatsDocuments($region, str_replace('{framework}', $framework, METRIC_SITES_FRAMEWORK), $count); + } } protected function createStatsDocuments(string $region, string $metric, int $value)