feat(usage): realtime data to api endpoint
This commit is contained in:
parent
ab6be33e6f
commit
03984860d5
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue