Added function usage tracking

This commit is contained in:
Eldad Fux
2020-07-21 13:33:23 +03:00
parent 1282be6132
commit c65ef9e6a8
9 changed files with 160 additions and 17 deletions
+18
View File
@@ -206,6 +206,7 @@ App::get('/v1/projects/:projectId/usage')
$requests = [];
$network = [];
$functions = [];
if ($client) {
$start = $period[$range]['start']->format(DateTime::RFC3339);
@@ -233,6 +234,17 @@ App::get('/v1/projects/:projectId/usage')
'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 "project"=\''.$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']),
];
}
}
// Users
@@ -289,6 +301,12 @@ App::get('/v1/projects/:projectId/usage')
return $item['value'];
}, $network)),
],
'functions' => [
'data' => $functions,
'total' => \array_sum(\array_map(function ($item) {
return $item['value'];
}, $functions)),
],
'collections' => [
'data' => $collections,
'total' => $collectionsTotal,