storage total stats
This commit is contained in:
parent
423ecb1071
commit
39d4924fe8
|
@ -296,6 +296,9 @@ App::get('/v1/projects/:projectId/usage')
|
||||||
|
|
||||||
$filesCount = $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['storage.files.count'])], 0, ['time'], [Database::ORDER_DESC]);
|
$filesCount = $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['storage.files.count'])], 0, ['time'], [Database::ORDER_DESC]);
|
||||||
$filesTotal = $filesCount ? $filesCount->getAttribute('value', 0) : 0;
|
$filesTotal = $filesCount ? $filesCount->getAttribute('value', 0) : 0;
|
||||||
|
|
||||||
|
$storageTotal = $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['storage.total'])], 0, ['time'], [Database::ORDER_DESC]);
|
||||||
|
$storage = $storageTotal ? $storageTotal->getAttribute('value', 0) : 0;
|
||||||
|
|
||||||
Authorization::reset();
|
Authorization::reset();
|
||||||
|
|
||||||
|
@ -335,24 +338,9 @@ App::get('/v1/projects/:projectId/usage')
|
||||||
'data' => [],
|
'data' => [],
|
||||||
'total' => $usersTotal,
|
'total' => $usersTotal,
|
||||||
],
|
],
|
||||||
// 'storage' => [
|
'storage' => [
|
||||||
// 'total' => $projectDB->getCount(
|
'total' => $storage,
|
||||||
// [
|
],
|
||||||
// 'attribute' => 'sizeOriginal',
|
|
||||||
// 'filters' => [
|
|
||||||
// '$collection=files',
|
|
||||||
// ],
|
|
||||||
// ]
|
|
||||||
// ) +
|
|
||||||
// $projectDB->getCount(
|
|
||||||
// [
|
|
||||||
// 'attribute' => 'size',
|
|
||||||
// 'filters' => [
|
|
||||||
// '$collection=tags',
|
|
||||||
// ],
|
|
||||||
// ]
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ use Utopia\Database\Validator\Authorization;
|
||||||
* database.documents.count
|
* database.documents.count
|
||||||
* database.collections.{collectionId}.documents.count
|
* database.collections.{collectionId}.documents.count
|
||||||
*
|
*
|
||||||
|
* Totals
|
||||||
|
*
|
||||||
|
* storage.total
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$cli
|
$cli
|
||||||
|
@ -263,6 +267,20 @@ $cli
|
||||||
|
|
||||||
foreach ($projects as $project) {
|
foreach ($projects as $project) {
|
||||||
$id = $project->getId();
|
$id = $project->getId();
|
||||||
|
|
||||||
|
// get total storage
|
||||||
|
$dbForProject->setNamespace('project_' . $id . '_internal');
|
||||||
|
$storageTotal = $dbForProject->sum('files', 'sizeOriginal') + $dbForProject->sum('tags', 'size');
|
||||||
|
|
||||||
|
$dbForProject->createDocument('stats', new Document([
|
||||||
|
'$id' => $dbForProject->getId(),
|
||||||
|
'period' => '15m',
|
||||||
|
'time' => time(),
|
||||||
|
'metric' => 'storage.total',
|
||||||
|
'value' => $storageTotal,
|
||||||
|
'type' => 1,
|
||||||
|
]));
|
||||||
|
|
||||||
$collections = [
|
$collections = [
|
||||||
'users' => [
|
'users' => [
|
||||||
'namespace' => 'internal',
|
'namespace' => 'internal',
|
||||||
|
@ -310,7 +328,7 @@ $cli
|
||||||
$dbForProject->setNamespace("project_{$id}_{$subOptions['namespace']}");
|
$dbForProject->setNamespace("project_{$id}_{$subOptions['namespace']}");
|
||||||
$count = $dbForProject->count($parent->getId());
|
$count = $dbForProject->count($parent->getId());
|
||||||
$subCollectionsCounts[$subCollection] = ($subCollectionCounts[$subCollection] ?? 0) + $count;
|
$subCollectionsCounts[$subCollection] = ($subCollectionCounts[$subCollection] ?? 0) + $count;
|
||||||
|
|
||||||
$dbForProject->setNamespace("project_{$id}_internal");
|
$dbForProject->setNamespace("project_{$id}_internal");
|
||||||
$dbForProject->createDocument('stats', new Document([
|
$dbForProject->createDocument('stats', new Document([
|
||||||
'$id' => $dbForProject->getId(),
|
'$id' => $dbForProject->getId(),
|
||||||
|
|
Loading…
Reference in a new issue