diff --git a/.env b/.env index ffd61bb934..ad4d4e9a46 100644 --- a/.env +++ b/.env @@ -62,9 +62,7 @@ _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 _APP_MAINTENANCE_RETENTION_ABUSE=86400 _APP_MAINTENANCE_RETENTION_AUDIT=1209600 _APP_MAINTENANCE_RETENTION_SCHEDULES=86400 -_APP_USAGE_TIMESERIES_INTERVAL=2 -_APP_USAGE_DATABASE_INTERVAL=15 -_APP_USAGE_AGGREGATION_INTERVAL=5 +_APP_USAGE_TIMESERIES_INTERVAL=60 _APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000 _APP_USAGE_STATS=enabled _APP_LOGGING_PROVIDER= diff --git a/Dockerfile b/Dockerfile index 4cec7233c9..44d1b5ff82 100755 --- a/Dockerfile +++ b/Dockerfile @@ -230,7 +230,6 @@ ENV _APP_SERVER=swoole \ _APP_SETUP=self-hosted \ _APP_VERSION=$VERSION \ _APP_USAGE_STATS=enabled \ - _APP_USAGE_AGGREGATION_INTERVAL=30 \ # 14 Days = 1209600 s _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 \ _APP_MAINTENANCE_RETENTION_AUDIT=1209600 \ diff --git a/app/console b/app/console index 2f6ba45084..4e2cecefb5 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 2f6ba45084bbc41666a6424a504cccb93c979e95 +Subproject commit 4e2cecefb571104f0dbbe5a578729f0e17a10242 diff --git a/app/controllers/api/project.php b/app/controllers/api/project.php index 92af7ccda0..40ad99f601 100644 --- a/app/controllers/api/project.php +++ b/app/controllers/api/project.php @@ -51,9 +51,10 @@ App::get('/v1/project/usage') 'project.$all.network.bandwidth', 'project.$all.storage.size', 'users.$all.count.total', - 'collections.$all.count.total', + 'databases.$all.count.total', 'documents.$all.count.total', 'executions.$all.compute.total', + 'buckets.$all.count.total' ]; $stats = []; @@ -102,10 +103,12 @@ App::get('/v1/project/usage') 'network' => $stats[$metrics[1]] ?? [], 'storage' => $stats[$metrics[2]] ?? [], 'users' => $stats[$metrics[3]] ?? [], - 'collections' => $stats[$metrics[4]] ?? [], + 'databases' => $stats[$metrics[4]] ?? [], 'documents' => $stats[$metrics[5]] ?? [], 'executions' => $stats[$metrics[6]] ?? [], + 'buckets' => $stats[$metrics[7]] ?? [], ]); + } $response->dynamic($usage, Response::MODEL_USAGE_PROJECT); diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index b98ff68e97..966a2b2bd2 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -489,7 +489,6 @@ services: - _APP_INFLUXDB_HOST - _APP_INFLUXDB_PORT - _APP_USAGE_TIMESERIES_INTERVAL - - _APP_USAGE_DATABASE_INTERVAL - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG @@ -521,7 +520,6 @@ services: - _APP_INFLUXDB_HOST - _APP_INFLUXDB_PORT - _APP_USAGE_TIMESERIES_INTERVAL - - _APP_USAGE_DATABASE_INTERVAL - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG diff --git a/docker-compose.yml b/docker-compose.yml index 914166a015..ce83066340 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -602,7 +602,6 @@ services: - _APP_DB_PASS - _APP_INFLUXDB_HOST - _APP_INFLUXDB_PORT - - _APP_USAGE_AGGREGATION_INTERVAL - _APP_REDIS_HOST - _APP_REDIS_PORT - _APP_REDIS_USER @@ -611,7 +610,6 @@ services: - _APP_CONNECTIONS_DB_PROJECT - _APP_CONNECTIONS_CACHE - _APP_USAGE_TIMESERIES_INTERVAL - - _APP_USAGE_DATABASE_INTERVAL - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG diff --git a/src/Appwrite/Platform/Tasks/Usage.php b/src/Appwrite/Platform/Tasks/Usage.php index 73686109d8..402211c8f2 100644 --- a/src/Appwrite/Platform/Tasks/Usage.php +++ b/src/Appwrite/Platform/Tasks/Usage.php @@ -2,8 +2,6 @@ namespace Appwrite\Platform\Tasks; -use Appwrite\Usage\Calculators\Aggregator; -use Appwrite\Usage\Calculators\Database; use Appwrite\Usage\Calculators\TimeSeries; use InfluxDB\Database as InfluxDatabase; use Utopia\App; @@ -34,7 +32,8 @@ class Usage extends Action protected function aggregateTimeseries(UtopiaDatabase $database, InfluxDatabase $influxDB, callable $logError): void { $interval = (int) App::getEnv('_APP_USAGE_TIMESERIES_INTERVAL', '30'); // 30 seconds (by default) - $usage = new TimeSeries($database, $influxDB, $logError); + $region = App::getEnv('region', 'default'); + $usage = new TimeSeries($region, $database, $influxDB, $logError); Console::loop(function () use ($interval, $usage) { $now = date('d-m-Y H:i:s', time()); @@ -49,25 +48,6 @@ class Usage extends Action }, $interval); } - protected function aggregateDatabase(UtopiaDatabase $database, callable $logError): void - { - $interval = (int) App::getEnv('_APP_USAGE_DATABASE_INTERVAL', '900'); // 15 minutes (by default) - $usage = new Database($database, $logError); - $aggregrator = new Aggregator($database, $logError); - - Console::loop(function () use ($interval, $usage, $aggregrator) { - $now = date('d-m-Y H:i:s', time()); - Console::info("[{$now}] Aggregating database usage every {$interval} seconds."); - $loopStart = microtime(true); - $usage->collect(); - $aggregrator->collect(); - $loopTook = microtime(true) - $loopStart; - $now = date('d-m-Y H:i:s', time()); - - Console::info("[{$now}] Aggregation took {$loopTook} seconds"); - }, $interval); - } - public function action(string $type, UtopiaDatabase $dbForConsole, InfluxDatabase $influxDB, callable $logError) { Console::title('Usage Aggregation V1'); @@ -79,9 +59,6 @@ class Usage extends Action case 'timeseries': $this->aggregateTimeseries($dbForConsole, $influxDB, $errorLogger); break; - case 'database': - $this->aggregateDatabase($dbForConsole, $errorLogger); - break; default: Console::error("Unsupported usage aggregation type"); }