Skip to content

Commit

Permalink
Add ConnectionCount and DriverTitle for monitoring commands
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Aug 12, 2024
1 parent 61aa6f1 commit 03b907f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ public function getDriverName()
return 'mongodb';
}

/** @inheritdoc */
public function getDriverTitle()
{
return 'MongoDB';
}

/** @inheritdoc */
protected function getDefaultPostProcessor()
{
Expand All @@ -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.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 03b907f

Please sign in to comment.