1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00

more stats from db

This commit is contained in:
Damodar Lohani 2021-08-17 12:18:51 +05:45
parent ee048caf93
commit 4bb911867c

View file

@ -322,79 +322,22 @@ App::get('/v1/projects/:projectId/usage')
]; ];
} }
$functions = array_reverse($functions); $functions = array_reverse($functions);
// $requests = [];
// $network = [];
// $functions = [];
// $client = $register->get('influxdb');
// if ($client) {
// $start = $period[$range]['start']->format(DateTime::RFC3339);
// $end = $period[$range]['end']->format(DateTime::RFC3339);
// $database = $client->selectDB('telegraf');
// // Requests
// $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_requests_all" WHERE time > \'' . $start . '\' AND time < \'' . $end . '\' AND "metric_type"=\'counter\' AND "projectId"=\'' . $project->getId() . '\' GROUP BY time(' . $period[$range]['group'] . ') FILL(null)');
// $points = $result->getPoints();
// foreach ($points as $point) {
// $requests[] = [
// 'value' => (!empty($point['value'])) ? $point['value'] : 0,
// 'date' => \strtotime($point['time']),
// ];
// }
// // Network
// $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_network_all" WHERE time > \'' . $start . '\' AND time < \'' . $end . '\' AND "metric_type"=\'counter\' AND "projectId"=\'' . $project->getId() . '\' GROUP BY time(' . $period[$range]['group'] . ') FILL(null)');
// $points = $result->getPoints();
// foreach ($points as $point) {
// $network[] = [
// 'value' => (!empty($point['value'])) ? $point['value'] : 0,
// 'date' => \strtotime($point['time']),
// ];
// }
// // Functions
// $result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \'' . $start . '\' AND time < \'' . $end . '\' AND "metric_type"=\'counter\' AND "projectId"=\'' . $project->getId() . '\' GROUP BY time(' . $period[$range]['group'] . ') FILL(null)');
// $points = $result->getPoints();
// foreach ($points as $point) {
// $functions[] = [
// 'value' => (!empty($point['value'])) ? $point['value'] : 0,
// 'date' => \strtotime($point['time']),
// ];
// }
// }
} else { } else {
$requests = []; $requests = [];
$network = []; $network = [];
$functions = []; $functions = [];
} }
// Users $usersCount = Authorization::skip(function () use ($dbForInternal) {
return $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['users.count'])], 0, ['time'], [Database::ORDER_DESC]);
});
$usersTotal = $usersCount ? $usersCount->getAttribute('value', 0) : 0;
// $projectDB->getCollection([ $collectionsCount = Authorization::skip(function () use ($dbForInternal, $period, $range) {
// 'limit' => 0, return $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['collections.count'])], 0, ['time'], [Database::ORDER_DESC]);
// 'offset' => 0, });
// 'filters' => [ $collectionsTotal = $collectionsCount ? $collectionsCount->getAttribute('value', 0) : 0;
// '$collection=users',
// ],
// ]);
// $usersTotal = $projectDB->getSum();
// // Documents
// $collections = $projectDB->getCollection([
// 'limit' => 100,
// 'offset' => 0,
// 'filters' => [
// '$collection=collections',
// ],
// ]);
// $collectionsTotal = $projectDB->getSum();
// $documents = []; // $documents = [];
@ -410,6 +353,11 @@ App::get('/v1/projects/:projectId/usage')
// $documents[] = ['name' => $collection['name'], 'total' => $projectDB->getSum()]; // $documents[] = ['name' => $collection['name'], 'total' => $projectDB->getSum()];
// } // }
$filesCount = Authorization::skip(function () use ($dbForInternal, $period, $range) {
return $dbForInternal->findOne('stats', [new Query('metric', Query::TYPE_EQUAL, ['files.count'])], 0, ['time'], [Database::ORDER_DESC]);
});
$filesTotal = $filesCount ? $filesCount->getAttribute('value', 0) : 0;
$response->json([ $response->json([
'range' => $range, 'range' => $range,
'requests' => [ 'requests' => [
@ -430,20 +378,24 @@ App::get('/v1/projects/:projectId/usage')
return $item['value']; return $item['value'];
}, $functions)), }, $functions)),
], ],
// 'collections' => [ 'collections' => [
// 'data' => $collections, 'data' => [],
// 'total' => $collectionsTotal, 'total' => $collectionsTotal,
// ], ],
'files' => [
'data' => [],
'total' => $filesTotal,
],
// 'documents' => [ // 'documents' => [
// 'data' => $documents, // 'data' => $documents,
// 'total' => \array_sum(\array_map(function ($item) { // 'total' => \array_sum(\array_map(function ($item) {
// return $item['total']; // return $item['total'];
// }, $documents)), // }, $documents)),
// ], // ],
// 'users' => [ 'users' => [
// 'data' => [], 'data' => [],
// 'total' => $usersTotal, 'total' => $usersTotal,
// ], ],
// 'storage' => [ // 'storage' => [
// 'total' => $projectDB->getCount( // 'total' => $projectDB->getCount(
// [ // [