1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

feat(usage): realtime data to api endpoint

This commit is contained in:
Torsten Dittmann 2021-06-08 19:02:28 +02:00
parent ab6be33e6f
commit 03984860d5

View file

@ -211,6 +211,8 @@ App::get('/v1/projects/:projectId/usage')
$requests = [];
$network = [];
$functions = [];
$realtimeConnections = [];
$realtimeMessages = [];
if ($client) {
$start = $period[$range]['start']->format(DateTime::RFC3339);
@ -249,11 +251,34 @@ App::get('/v1/projects/:projectId/usage')
'date' => \strtotime($point['time']),
];
}
// Realtime Connections
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_realtime_clients" 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) {
$realtimeConnections[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
];
}
// Realtime Messages
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_realtime_messages" 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) {
$realtimeMessages[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
];
}
}
} else {
$requests = [];
$network = [];
$functions = [];
$realtimeConnections = [];
$realtimeMessages = [];
}
@ -318,6 +343,18 @@ App::get('/v1/projects/:projectId/usage')
return $item['value'];
}, $functions)),
],
'realtimeConnections' => [
'data' => $realtimeConnections,
'total' => \array_sum(\array_map(function ($item) {
return $item['value'];
}, $realtimeConnections)),
],
'realtimeMessages' => [
'data' => $realtimeMessages,
'total' => \array_sum(\array_map(function ($item) {
return $item['value'];
}, $realtimeMessages)),
],
'collections' => [
'data' => $collections,
'total' => $collectionsTotal,