Skip to content

Commit 2b152a1

Browse files
authored
feat: stats 增加使用中的连接数 (#115)
1 parent 37d8d8c commit 2b152a1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/client.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ export class RDSClient extends Operator {
9999
}
100100

101101
get stats() {
102+
const acquiringConnections = this.#pool._acquiringConnections.length;
103+
const allConnections = this.#pool._allConnections.length;
104+
const freeConnections = this.#pool._freeConnections.length;
105+
const connectionQueue = this.#pool._connectionQueue.length;
106+
const busyConnections = allConnections - freeConnections - acquiringConnections;
102107
return {
103-
acquiringConnections: this.#pool._acquiringConnections.length,
104-
allConnections: this.#pool._allConnections.length,
105-
freeConnections: this.#pool._freeConnections.length,
106-
connectionQueue: this.#pool._connectionQueue.length,
108+
acquiringConnections,
109+
allConnections,
110+
freeConnections,
111+
connectionQueue,
112+
busyConnections,
107113
};
108114
}
109115

test/client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,11 +1340,11 @@ describe('test/client.test.ts', () => {
13401340
describe('get stats()', () => {
13411341
it('should get client stats', async () => {
13421342
const stats = db.stats;
1343-
console.log(stats);
13441343
assert.equal(typeof stats.acquiringConnections, 'number');
13451344
assert.equal(typeof stats.allConnections, 'number');
13461345
assert.equal(typeof stats.freeConnections, 'number');
13471346
assert.equal(typeof stats.connectionQueue, 'number');
1347+
assert.equal(typeof stats.busyConnections, 'number');
13481348
});
13491349
});
13501350

0 commit comments

Comments
 (0)