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