From 03b907fbab65d4da375fc0731b439df26054c30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 23 Jul 2024 22:58:31 +0200 Subject: [PATCH] Add ConnectionCount and DriverTitle for monitoring commands --- src/Connection.php | 14 ++++++++++++++ tests/ConnectionTest.php | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Connection.php b/src/Connection.php index 9b4cc26ed..a0affa56a 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -294,6 +294,12 @@ public function getDriverName() return 'mongodb'; } + /** @inheritdoc */ + public function getDriverTitle() + { + return 'MongoDB'; + } + /** @inheritdoc */ protected function getDefaultPostProcessor() { @@ -320,6 +326,14 @@ public function setDatabase(Database $db) $this->db = $db; } + /** @inheritdoc */ + public function threadCount() + { + $status = $this->db->command(['serverStatus' => 1])->toArray(); + + return $status[0]['connections']['current']; + } + /** * Dynamically pass methods to the connection. * diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 214050840..ac4cc78fc 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -25,6 +25,9 @@ public function testConnection() { $connection = DB::connection('mongodb'); $this->assertInstanceOf(Connection::class, $connection); + + $this->assertSame('mongodb', $connection->getDriverName()); + $this->assertSame('MongoDB', $connection->getDriverTitle()); } public function testReconnect() @@ -305,4 +308,12 @@ public function testServerVersion() $version = DB::connection('mongodb')->getServerVersion(); $this->assertIsString($version); } + + public function testThreadsCount() + { + $threads = DB::connection('mongodb')->threadCount(); + + $this->assertIsInt($threads); + $this->assertGreaterThanOrEqual(1, $threads); + } }