fix: issues with usage
This commit is contained in:
parent
71bb70dec4
commit
373e230ab0
7 changed files with 9 additions and 36 deletions
4
.env
4
.env
|
@ -62,9 +62,7 @@ _APP_MAINTENANCE_RETENTION_EXECUTION=1209600
|
||||||
_APP_MAINTENANCE_RETENTION_ABUSE=86400
|
_APP_MAINTENANCE_RETENTION_ABUSE=86400
|
||||||
_APP_MAINTENANCE_RETENTION_AUDIT=1209600
|
_APP_MAINTENANCE_RETENTION_AUDIT=1209600
|
||||||
_APP_MAINTENANCE_RETENTION_SCHEDULES=86400
|
_APP_MAINTENANCE_RETENTION_SCHEDULES=86400
|
||||||
_APP_USAGE_TIMESERIES_INTERVAL=2
|
_APP_USAGE_TIMESERIES_INTERVAL=60
|
||||||
_APP_USAGE_DATABASE_INTERVAL=15
|
|
||||||
_APP_USAGE_AGGREGATION_INTERVAL=5
|
|
||||||
_APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000
|
_APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000
|
||||||
_APP_USAGE_STATS=enabled
|
_APP_USAGE_STATS=enabled
|
||||||
_APP_LOGGING_PROVIDER=
|
_APP_LOGGING_PROVIDER=
|
||||||
|
|
|
@ -230,7 +230,6 @@ ENV _APP_SERVER=swoole \
|
||||||
_APP_SETUP=self-hosted \
|
_APP_SETUP=self-hosted \
|
||||||
_APP_VERSION=$VERSION \
|
_APP_VERSION=$VERSION \
|
||||||
_APP_USAGE_STATS=enabled \
|
_APP_USAGE_STATS=enabled \
|
||||||
_APP_USAGE_AGGREGATION_INTERVAL=30 \
|
|
||||||
# 14 Days = 1209600 s
|
# 14 Days = 1209600 s
|
||||||
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600 \
|
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600 \
|
||||||
_APP_MAINTENANCE_RETENTION_AUDIT=1209600 \
|
_APP_MAINTENANCE_RETENTION_AUDIT=1209600 \
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2f6ba45084bbc41666a6424a504cccb93c979e95
|
Subproject commit 4e2cecefb571104f0dbbe5a578729f0e17a10242
|
|
@ -51,9 +51,10 @@ App::get('/v1/project/usage')
|
||||||
'project.$all.network.bandwidth',
|
'project.$all.network.bandwidth',
|
||||||
'project.$all.storage.size',
|
'project.$all.storage.size',
|
||||||
'users.$all.count.total',
|
'users.$all.count.total',
|
||||||
'collections.$all.count.total',
|
'databases.$all.count.total',
|
||||||
'documents.$all.count.total',
|
'documents.$all.count.total',
|
||||||
'executions.$all.compute.total',
|
'executions.$all.compute.total',
|
||||||
|
'buckets.$all.count.total'
|
||||||
];
|
];
|
||||||
|
|
||||||
$stats = [];
|
$stats = [];
|
||||||
|
@ -102,10 +103,12 @@ App::get('/v1/project/usage')
|
||||||
'network' => $stats[$metrics[1]] ?? [],
|
'network' => $stats[$metrics[1]] ?? [],
|
||||||
'storage' => $stats[$metrics[2]] ?? [],
|
'storage' => $stats[$metrics[2]] ?? [],
|
||||||
'users' => $stats[$metrics[3]] ?? [],
|
'users' => $stats[$metrics[3]] ?? [],
|
||||||
'collections' => $stats[$metrics[4]] ?? [],
|
'databases' => $stats[$metrics[4]] ?? [],
|
||||||
'documents' => $stats[$metrics[5]] ?? [],
|
'documents' => $stats[$metrics[5]] ?? [],
|
||||||
'executions' => $stats[$metrics[6]] ?? [],
|
'executions' => $stats[$metrics[6]] ?? [],
|
||||||
|
'buckets' => $stats[$metrics[7]] ?? [],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$response->dynamic($usage, Response::MODEL_USAGE_PROJECT);
|
$response->dynamic($usage, Response::MODEL_USAGE_PROJECT);
|
||||||
|
|
|
@ -489,7 +489,6 @@ services:
|
||||||
- _APP_INFLUXDB_HOST
|
- _APP_INFLUXDB_HOST
|
||||||
- _APP_INFLUXDB_PORT
|
- _APP_INFLUXDB_PORT
|
||||||
- _APP_USAGE_TIMESERIES_INTERVAL
|
- _APP_USAGE_TIMESERIES_INTERVAL
|
||||||
- _APP_USAGE_DATABASE_INTERVAL
|
|
||||||
- _APP_LOGGING_PROVIDER
|
- _APP_LOGGING_PROVIDER
|
||||||
- _APP_LOGGING_CONFIG
|
- _APP_LOGGING_CONFIG
|
||||||
|
|
||||||
|
@ -521,7 +520,6 @@ services:
|
||||||
- _APP_INFLUXDB_HOST
|
- _APP_INFLUXDB_HOST
|
||||||
- _APP_INFLUXDB_PORT
|
- _APP_INFLUXDB_PORT
|
||||||
- _APP_USAGE_TIMESERIES_INTERVAL
|
- _APP_USAGE_TIMESERIES_INTERVAL
|
||||||
- _APP_USAGE_DATABASE_INTERVAL
|
|
||||||
- _APP_LOGGING_PROVIDER
|
- _APP_LOGGING_PROVIDER
|
||||||
- _APP_LOGGING_CONFIG
|
- _APP_LOGGING_CONFIG
|
||||||
|
|
||||||
|
|
|
@ -602,7 +602,6 @@ services:
|
||||||
- _APP_DB_PASS
|
- _APP_DB_PASS
|
||||||
- _APP_INFLUXDB_HOST
|
- _APP_INFLUXDB_HOST
|
||||||
- _APP_INFLUXDB_PORT
|
- _APP_INFLUXDB_PORT
|
||||||
- _APP_USAGE_AGGREGATION_INTERVAL
|
|
||||||
- _APP_REDIS_HOST
|
- _APP_REDIS_HOST
|
||||||
- _APP_REDIS_PORT
|
- _APP_REDIS_PORT
|
||||||
- _APP_REDIS_USER
|
- _APP_REDIS_USER
|
||||||
|
@ -611,7 +610,6 @@ services:
|
||||||
- _APP_CONNECTIONS_DB_PROJECT
|
- _APP_CONNECTIONS_DB_PROJECT
|
||||||
- _APP_CONNECTIONS_CACHE
|
- _APP_CONNECTIONS_CACHE
|
||||||
- _APP_USAGE_TIMESERIES_INTERVAL
|
- _APP_USAGE_TIMESERIES_INTERVAL
|
||||||
- _APP_USAGE_DATABASE_INTERVAL
|
|
||||||
- _APP_LOGGING_PROVIDER
|
- _APP_LOGGING_PROVIDER
|
||||||
- _APP_LOGGING_CONFIG
|
- _APP_LOGGING_CONFIG
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace Appwrite\Platform\Tasks;
|
namespace Appwrite\Platform\Tasks;
|
||||||
|
|
||||||
use Appwrite\Usage\Calculators\Aggregator;
|
|
||||||
use Appwrite\Usage\Calculators\Database;
|
|
||||||
use Appwrite\Usage\Calculators\TimeSeries;
|
use Appwrite\Usage\Calculators\TimeSeries;
|
||||||
use InfluxDB\Database as InfluxDatabase;
|
use InfluxDB\Database as InfluxDatabase;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
@ -34,7 +32,8 @@ class Usage extends Action
|
||||||
protected function aggregateTimeseries(UtopiaDatabase $database, InfluxDatabase $influxDB, callable $logError): void
|
protected function aggregateTimeseries(UtopiaDatabase $database, InfluxDatabase $influxDB, callable $logError): void
|
||||||
{
|
{
|
||||||
$interval = (int) App::getEnv('_APP_USAGE_TIMESERIES_INTERVAL', '30'); // 30 seconds (by default)
|
$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) {
|
Console::loop(function () use ($interval, $usage) {
|
||||||
$now = date('d-m-Y H:i:s', time());
|
$now = date('d-m-Y H:i:s', time());
|
||||||
|
@ -49,25 +48,6 @@ class Usage extends Action
|
||||||
}, $interval);
|
}, $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)
|
public function action(string $type, UtopiaDatabase $dbForConsole, InfluxDatabase $influxDB, callable $logError)
|
||||||
{
|
{
|
||||||
Console::title('Usage Aggregation V1');
|
Console::title('Usage Aggregation V1');
|
||||||
|
@ -79,9 +59,6 @@ class Usage extends Action
|
||||||
case 'timeseries':
|
case 'timeseries':
|
||||||
$this->aggregateTimeseries($dbForConsole, $influxDB, $errorLogger);
|
$this->aggregateTimeseries($dbForConsole, $influxDB, $errorLogger);
|
||||||
break;
|
break;
|
||||||
case 'database':
|
|
||||||
$this->aggregateDatabase($dbForConsole, $errorLogger);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
Console::error("Unsupported usage aggregation type");
|
Console::error("Unsupported usage aggregation type");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue