@multisystemsuite/connection-monitor
v2.1.0
Published
Connection pool monitoring and leak detection
Readme
@multisystemsuite/connection-monitor
Monitor connection pools: active/idle/waiting counts, leak detection, hold-time analytics, exhaustion alerts, and idle connection cleanup hints.
Version: 1.0.1 · License: MIT
npm readme: @multisystemsuite/connection-monitor on npm
Installation
pnpm add @multisystemsuite/connection-monitorQuick start
import { ConnectionMonitor } from '@multisystemsuite/connection-monitor';
const monitor = new ConnectionMonitor({
leakThresholdMs: 60_000,
idleTimeoutMs: 300_000,
});
const connId = monitor.acquire();
try {
await runQuery();
} finally {
monitor.release(connId);
}
monitor.updatePool({ active: 8, idle: 2, waiting: 3, max: 10 });
console.log(monitor.isExhausted()); // true if waiting or at maxConfiguration
| Option | Default | Description |
|--------|---------|-------------|
| leakThresholdMs | 60000 | Flag connections held longer than this |
| idleTimeoutMs | 300000 | Used for idle cleanup heuristic |
API reference
| Method | Description |
|--------|-------------|
| acquire(id?) | Track new connection; returns id |
| release(connId) | Mark connection released |
| updatePool(stats) | Set pool counters |
| detectLeaks() | Connections held past threshold |
| getIdleConnectionsToClose() | Suggested idle connections to drop |
| getAnalytics() | Totals, leaks, avg hold time |
| getPoolStats() | Current pool snapshot |
| isExhausted() | true if waiting > 0 or active ≥ max |
ConnectionAnalytics
{
totalAcquired: number;
totalReleased: number;
leaks: TrackedConnection[];
avgHoldTimeMs: number;
}Integration with pool library
pool.on('acquire', () => monitor.acquire());
pool.on('release', (conn) => monitor.release(connIdMap.get(conn)));
setInterval(() => {
monitor.updatePool({
active: pool.totalCount - pool.idleCount,
idle: pool.idleCount,
waiting: pool.waitingCount,
max: pool.options.max,
});
}, 5000);Related packages
See the @multisystemsuite org on npm.
npm
- Package: @multisystemsuite/connection-monitor
- Install:
npm install @multisystemsuite/connection-monitor
