Skip to content

Commit d37750f

Browse files
committed
Add ConnectionCount and DriverTitle for monitoring commands
1 parent 61aa6f1 commit d37750f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Connection.php

+14
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ public function getDriverName()
294294
return 'mongodb';
295295
}
296296

297+
/** @inheritdoc */
298+
public function getDriverTitle()
299+
{
300+
return 'MongoDB';
301+
}
302+
297303
/** @inheritdoc */
298304
protected function getDefaultPostProcessor()
299305
{
@@ -320,6 +326,14 @@ public function setDatabase(Database $db)
320326
$this->db = $db;
321327
}
322328

329+
/** @inheritdoc */
330+
public function threadCount()
331+
{
332+
$status = $this->db->command(['serverStatus' => 1])->toArray();
333+
334+
return $status[0]['connections']['current'];
335+
}
336+
323337
/**
324338
* Dynamically pass methods to the connection.
325339
*

tests/ConnectionTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,12 @@ public function testServerVersion()
305305
$version = DB::connection('mongodb')->getServerVersion();
306306
$this->assertIsString($version);
307307
}
308+
309+
public function testThreadsCount()
310+
{
311+
$threads = DB::connection('mongodb')->threadCount();
312+
313+
$this->assertIsInt($threads);
314+
$this->assertGreaterThanOrEqual(1, $threads);
315+
}
308316
}

0 commit comments

Comments
 (0)