metrics.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ConnectionPoolMetrics = void 0;
  4. /** @internal */
  5. class ConnectionPoolMetrics {
  6. constructor() {
  7. this.txnConnections = 0;
  8. this.cursorConnections = 0;
  9. this.otherConnections = 0;
  10. }
  11. static { this.TXN = 'txn'; }
  12. static { this.CURSOR = 'cursor'; }
  13. static { this.OTHER = 'other'; }
  14. /**
  15. * Mark a connection as pinned for a specific operation.
  16. */
  17. markPinned(pinType) {
  18. if (pinType === ConnectionPoolMetrics.TXN) {
  19. this.txnConnections += 1;
  20. }
  21. else if (pinType === ConnectionPoolMetrics.CURSOR) {
  22. this.cursorConnections += 1;
  23. }
  24. else {
  25. this.otherConnections += 1;
  26. }
  27. }
  28. /**
  29. * Unmark a connection as pinned for an operation.
  30. */
  31. markUnpinned(pinType) {
  32. if (pinType === ConnectionPoolMetrics.TXN) {
  33. this.txnConnections -= 1;
  34. }
  35. else if (pinType === ConnectionPoolMetrics.CURSOR) {
  36. this.cursorConnections -= 1;
  37. }
  38. else {
  39. this.otherConnections -= 1;
  40. }
  41. }
  42. /**
  43. * Return information about the cmap metrics as a string.
  44. */
  45. info(maxPoolSize) {
  46. return ('Timed out while checking out a connection from connection pool: ' +
  47. `maxPoolSize: ${maxPoolSize}, ` +
  48. `connections in use by cursors: ${this.cursorConnections}, ` +
  49. `connections in use by transactions: ${this.txnConnections}, ` +
  50. `connections in use by other operations: ${this.otherConnections}`);
  51. }
  52. /**
  53. * Reset the metrics to the initial values.
  54. */
  55. reset() {
  56. this.txnConnections = 0;
  57. this.cursorConnections = 0;
  58. this.otherConnections = 0;
  59. }
  60. }
  61. exports.ConnectionPoolMetrics = ConnectionPoolMetrics;
  62. //# sourceMappingURL=metrics.js.map