1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00

feat(usage): some refactoring

This commit is contained in:
Christy Jacob 2021-08-20 15:34:57 +05:30
parent aefbdb0597
commit f3074bc024
2 changed files with 32 additions and 28 deletions

View file

@ -316,35 +316,37 @@ App::get('/v1/database/usage')
$stats[$metric] = array_reverse($stats[$metric]);
}
$documentsCount = $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['database.documents.count'])], 0, ['time'], [Database::ORDER_DESC]);
$documentsTotal = $documentsCount ? $documentsCount->getAttribute('value', 0) : 0;
$collectionsCount = $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['n
'])], 0, ['time'], [Database::ORDER_DESC]);
$collectionsTotal = $collectionsCount ? $collectionsCount->getAttribute('value', 0) : 0;
Authorization::reset();
$response->json([
'range' => $range,
'stats' => $stats,
'requests' => [
'data' => $stats['requests'] ?? [],
'total' => \array_sum(\array_map(function ($item) {
return $item['value'];
}, $stats['requests'] ?? [])),
],
'documents' => [
'data' => [],
'total' => $documentsTotal,
],
'collections' => [
'data' => [],
'total' => $collectionsTotal,
]
]);
} else {
$response->json([]);
}
$documentsCount = $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['database.documents.count'])], 0, ['time'], [Database::ORDER_DESC]);
$documentsTotal = $documentsCount ? $documentsCount->getAttribute('value', 0) : 0;
$collectionsCount = $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['n
'])], 0, ['time'], [Database::ORDER_DESC]);
$collectionsTotal = $collectionsCount ? $collectionsCount->getAttribute('value', 0) : 0;
Authorization::reset();
$response->json([
'range' => $range,
'stats' => $stats,
'requests' => [
'data' => $stats['requests'] ?? [],
'total' => \array_sum(\array_map(function ($item) {
return $item['value'];
}, $stats['requests'] ?? [])),
],
'documents' => [
'data' => [],
'total' => $documentsTotal,
],
'collections' => [
'data' => [],
'total' => $collectionsTotal,
]
]);
});

View file

@ -323,6 +323,8 @@ App::get('/v1/functions/:functionId/usage2')
$stats[$metric] = array_reverse($stats[$metric]);
}
Authorization::reset();
$executions = $stats["functions.$functionId.executions"] ?? [];
$failures = $stats["functions.$functionId.failures"] ?? [];