Skip to content

Commit

Permalink
🐛 FIX: Export db pool stats (ali-sdk#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Dec 14, 2022
1 parent 842a37e commit add4669
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class RDSClient extends Operator {
return await this.#pool.query(sql);
}

get stats() {
return {
acquiringConnections: this.#pool._acquiringConnections.length,
allConnections: this.#pool._allConnections.length,
freeConnections: this.#pool._freeConnections.length,
connectionQueue: this.#pool._connectionQueue.length,
};
}

async getConnection() {
try {
const conn = await this.#pool.getConnection();
Expand Down
11 changes: 11 additions & 0 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,17 @@ describe('test/client.test.js', () => {
});
});

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');
});
});

describe('count()', () => {
before(async () => {
await db.query(`insert into ??(name, email, gmt_create, gmt_modified)
Expand Down

0 comments on commit add4669

Please sign in to comment.