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]);
|
||||
$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();
|
||||
|
||||
|
@ -335,24 +338,9 @@ App::get('/v1/projects/:projectId/usage')
|
|||
'data' => [],
|
||||
'total' => $usersTotal,
|
||||
],
|
||||
// 'storage' => [
|
||||
// 'total' => $projectDB->getCount(
|
||||
// [
|
||||
// 'attribute' => 'sizeOriginal',
|
||||
// 'filters' => [
|
||||
// '$collection=files',
|
||||
// ],
|
||||
// ]
|
||||
// ) +
|
||||
// $projectDB->getCount(
|
||||
// [
|
||||
// 'attribute' => 'size',
|
||||
// 'filters' => [
|
||||
// '$collection=tags',
|
||||
// ],
|
||||
// ]
|
||||
// ),
|
||||
// ],
|
||||
'storage' => [
|
||||
'total' => $storage,
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
|
@ -51,6 +51,10 @@ use Utopia\Database\Validator\Authorization;
|
|||
* database.documents.count
|
||||
* database.collections.{collectionId}.documents.count
|
||||
*
|
||||
* Totals
|
||||
*
|
||||
* storage.total
|
||||
*
|
||||
*/
|
||||
|
||||
$cli
|
||||
|
@ -263,6 +267,20 @@ $cli
|
|||
|
||||
foreach ($projects as $project) {
|
||||
$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 = [
|
||||
'users' => [
|
||||
'namespace' => 'internal',
|
||||
|
@ -310,7 +328,7 @@ $cli
|
|||
$dbForProject->setNamespace("project_{$id}_{$subOptions['namespace']}");
|
||||
$count = $dbForProject->count($parent->getId());
|
||||
$subCollectionsCounts[$subCollection] = ($subCollectionCounts[$subCollection] ?? 0) + $count;
|
||||
|
||||
|
||||
$dbForProject->setNamespace("project_{$id}_internal");
|
||||
$dbForProject->createDocument('stats', new Document([
|
||||
'$id' => $dbForProject->getId(),
|
||||
|
|
Loading…
Reference in a new issue