Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stats 增加使用中的连接数 #115

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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