From b740edf1091e090a6276d16cbdab66f69365812e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Fri, 23 Jan 2026 17:50:48 +0100 Subject: [PATCH 1/2] feat(openmetrics): Add basic call metrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- appinfo/info.xml | 6 +++ lib/Command/Monitor/HasActiveCalls.php | 31 ++++----------- lib/OpenMetrics/ActiveCalls.php | 49 ++++++++++++++++++++++++ lib/OpenMetrics/SessionsInCalls.php | 49 ++++++++++++++++++++++++ lib/Service/MetricsService.php | 52 ++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 24 deletions(-) create mode 100644 lib/OpenMetrics/ActiveCalls.php create mode 100644 lib/OpenMetrics/SessionsInCalls.php create mode 100644 lib/Service/MetricsService.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 3bdef38ee3f..9929b436ad7 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -167,4 +167,10 @@ OCA\Talk\Collaboration\Collaborators\RoomPlugin + + + OCA\Talk\OpenMetrics\ActiveCalls + OCA\Talk\OpenMetrics\SessionsInCalls + + diff --git a/lib/Command/Monitor/HasActiveCalls.php b/lib/Command/Monitor/HasActiveCalls.php index 1d27278d535..6ea07b072d5 100644 --- a/lib/Command/Monitor/HasActiveCalls.php +++ b/lib/Command/Monitor/HasActiveCalls.php @@ -9,15 +9,14 @@ namespace OCA\Talk\Command\Monitor; use OC\Core\Command\Base; -use OCA\Talk\Participant; -use OCP\IDBConnection; +use OCA\Talk\Service\MetricsService; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class HasActiveCalls extends Base { public function __construct( - protected IDBConnection $connection, + protected MetricsService $metricsService, ) { parent::__construct(); } @@ -33,15 +32,7 @@ protected function configure(): void { } protected function execute(InputInterface $input, OutputInterface $output): int { - $query = $this->connection->getQueryBuilder(); - - $query->select($query->func()->count('*', 'num_calls')) - ->from('talk_rooms') - ->where($query->expr()->isNotNull('active_since')); - - $result = $query->executeQuery(); - $numCalls = (int)$result->fetchColumn(); - $result->closeCursor(); + $numCalls = $this->metricsService->getNumberOfActiveCalls(); if ($numCalls === 0) { if ($input->getOption('output') === 'plain') { @@ -53,21 +44,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - $query = $this->connection->getQueryBuilder(); - $query->select($query->func()->count('*', 'num_participants')) - ->from('talk_sessions') - ->where($query->expr()->gt('in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED))) - ->andWhere($query->expr()->gt('last_ping', $query->createNamedParameter(time() - 60))); - - $result = $query->executeQuery(); - $numParticipants = (int)$result->fetchColumn(); - $result->closeCursor(); - + $numSessions = $this->metricsService->getNumberOfSessionsInCalls(); + // We keep "participants" here, to not break scripting done with that command if ($input->getOption('output') === 'plain') { - $output->writeln(sprintf('There are currently %1$d calls in progress with %2$d participants', $numCalls, $numParticipants)); + $output->writeln(sprintf('There are currently %1$d calls in progress with %2$d participants', $numCalls, $numSessions)); } else { - $data = ['calls' => $numCalls, 'participants' => $numParticipants]; + $data = ['calls' => $numCalls, 'participants' => $numSessions]; $this->writeArrayInOutputFormat($input, $output, $data); } return 1; diff --git a/lib/OpenMetrics/ActiveCalls.php b/lib/OpenMetrics/ActiveCalls.php new file mode 100644 index 00000000000..b85d6b1ae1b --- /dev/null +++ b/lib/OpenMetrics/ActiveCalls.php @@ -0,0 +1,49 @@ +metricsService->getNumberOfActiveCalls(), [], time()); + } +} diff --git a/lib/OpenMetrics/SessionsInCalls.php b/lib/OpenMetrics/SessionsInCalls.php new file mode 100644 index 00000000000..fc4fbc25a7c --- /dev/null +++ b/lib/OpenMetrics/SessionsInCalls.php @@ -0,0 +1,49 @@ +metricsService->getNumberOfSessionsInCalls(), [], time()); + } +} diff --git a/lib/Service/MetricsService.php b/lib/Service/MetricsService.php new file mode 100644 index 00000000000..89c7ea898b4 --- /dev/null +++ b/lib/Service/MetricsService.php @@ -0,0 +1,52 @@ +connection->getQueryBuilder(); + + $query->select($query->func()->count('*', 'num_calls')) + ->from('talk_rooms') + ->where($query->expr()->isNotNull('active_since')); + + $result = $query->executeQuery(); + $numCalls = (int)$result->fetchOne(); + $result->closeCursor(); + + return $numCalls; + } + + public function getNumberOfSessionsInCalls(): int { + $query = $this->connection->getQueryBuilder(); + $query->select($query->func()->count('*', 'num_sessions')) + ->from('talk_sessions') + ->where($query->expr()->gt('in_call', $query->createNamedParameter(Participant::FLAG_DISCONNECTED))) + ->andWhere($query->expr()->gt('last_ping', $query->createNamedParameter(time() - 60))); + + $result = $query->executeQuery(); + $numSessions = (int)$result->fetchColumn(); + $result->closeCursor(); + + return $numSessions; + } + +} From 352c0c210f447bad1262677a5ff1114cf896870a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Mon, 26 Jan 2026 22:38:44 +0100 Subject: [PATCH 2/2] fix: Unit must be a suffix of metric name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- appinfo/info.xml | 2 +- lib/OpenMetrics/{SessionsInCalls.php => InCallSessions.php} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename lib/OpenMetrics/{SessionsInCalls.php => InCallSessions.php} (91%) diff --git a/appinfo/info.xml b/appinfo/info.xml index 9929b436ad7..bdedec73ff9 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -170,7 +170,7 @@ OCA\Talk\OpenMetrics\ActiveCalls - OCA\Talk\OpenMetrics\SessionsInCalls + OCA\Talk\OpenMetrics\InCallSessions diff --git a/lib/OpenMetrics/SessionsInCalls.php b/lib/OpenMetrics/InCallSessions.php similarity index 91% rename from lib/OpenMetrics/SessionsInCalls.php rename to lib/OpenMetrics/InCallSessions.php index fc4fbc25a7c..48d3e283f19 100644 --- a/lib/OpenMetrics/SessionsInCalls.php +++ b/lib/OpenMetrics/InCallSessions.php @@ -16,7 +16,7 @@ use OCP\OpenMetrics\MetricType; use Override; -class SessionsInCalls implements IMetricFamily { +class InCallSessions implements IMetricFamily { public function __construct( private MetricsService $metricsService, ) { @@ -24,7 +24,7 @@ public function __construct( #[Override] public function name(): string { - return 'talk_sessions_in_calls'; + return 'talk_in_call_sessions'; } #[Override]