Skip to content

Commit

Permalink
feat: stats 增加使用中的连接数 (ali-sdk#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
qile222 committed Jul 31, 2023
1 parent 37d8d8c commit 2b152a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down

0 comments on commit 2b152a1

Please sign in to comment.