From 2b152a14b39291665c74910f2fe803d8318843db Mon Sep 17 00:00:00 2001 From: qile222 Date: Mon, 31 Jul 2023 12:38:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20stats=20=E5=A2=9E=E5=8A=A0=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=B8=AD=E7=9A=84=E8=BF=9E=E6=8E=A5=E6=95=B0=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client.ts | 14 ++++++++++---- test/client.test.ts | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/client.ts b/src/client.ts index 71ec03d..36a7155 100644 --- a/src/client.ts +++ b/src/client.ts @@ -99,11 +99,17 @@ export class RDSClient extends Operator { } get stats() { + const acquiringConnections = this.#pool._acquiringConnections.length; + const allConnections = this.#pool._allConnections.length; + const freeConnections = this.#pool._freeConnections.length; + const connectionQueue = this.#pool._connectionQueue.length; + const busyConnections = allConnections - freeConnections - acquiringConnections; return { - acquiringConnections: this.#pool._acquiringConnections.length, - allConnections: this.#pool._allConnections.length, - freeConnections: this.#pool._freeConnections.length, - connectionQueue: this.#pool._connectionQueue.length, + acquiringConnections, + allConnections, + freeConnections, + connectionQueue, + busyConnections, }; } diff --git a/test/client.test.ts b/test/client.test.ts index accfe2a..e1160f1 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -1340,11 +1340,11 @@ describe('test/client.test.ts', () => { describe('get stats()', () => { it('should get client stats', async () => { const stats = db.stats; - console.log(stats); assert.equal(typeof stats.acquiringConnections, 'number'); assert.equal(typeof stats.allConnections, 'number'); assert.equal(typeof stats.freeConnections, 'number'); assert.equal(typeof stats.connectionQueue, 'number'); + assert.equal(typeof stats.busyConnections, 'number'); }); });