diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 0b9eb64ff0..9d2a28f04f 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -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,