UNPKG

6.38 kBJavaScriptView Raw
1// Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3//-----------------------------------------------------------------------------
4//
5// This software is dual-licensed to you under the Universal Permissive License
6// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8// either license.
9//
10// If you elect to accept the software under the Apache License, Version 2.0,
11// the following applies:
12//
13// Licensed under the Apache License, Version 2.0 (the "License");
14// you may not use this file except in compliance with the License.
15// You may obtain a copy of the License at
16//
17// https://www.apache.org/licenses/LICENSE-2.0
18//
19// Unless required by applicable law or agreed to in writing, software
20// distributed under the License is distributed on an "AS IS" BASIS,
21// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22// See the License for the specific language governing permissions and
23// limitations under the License.
24//
25//-----------------------------------------------------------------------------
26
27'use strict';
28
29const process = require('process');
30const settings = require('./settings.js');
31
32//-----------------------------------------------------------------------------
33// class PoolStatistics
34// collection of statistics metrics for Pool object
35//-----------------------------------------------------------------------------
36
37class PoolStatistics {
38
39 constructor(pool) {
40 let averageTimeInQueue = 0;
41
42 if (pool._totalRequestsEnqueued !== 0) {
43 averageTimeInQueue = Math.round(pool._totalTimeInQueue /
44 pool._totalRequestsEnqueued);
45 }
46
47 this.gatheredDate = Date.now ();
48 this.upTime = this.gatheredDate - pool._createdDate;
49 this.upTimeSinceReset = this.gatheredDate - pool._timeOfReset;
50 this.connectionRequests = pool._totalConnectionRequests;
51 this.requestsEnqueued = pool._totalRequestsEnqueued;
52 this.requestsDequeued = pool._totalRequestsDequeued;
53 this.failedRequests = pool._totalFailedRequests;
54 this.rejectedRequests = pool._totalRequestsRejected;
55 this.requestTimeouts = pool._totalRequestTimeouts;
56 this.maximumQueueLength = pool._maximumQueueLength;
57 this.currentQueueLength = pool._connRequestQueue.length;
58 this.timeInQueue = pool._totalTimeInQueue;
59 this.minimumTimeInQueue = pool._minTimeInQueue;
60 this.maximumTimeInQueue = pool._maxTimeInQueue;
61 this.averageTimeInQueue = averageTimeInQueue;
62 this.connectionsInUse = pool.connectionsInUse;
63 this.connectionsOpen = pool.connectionsOpen;
64 this.connectString = pool.connectString;
65 this.edition = pool.edition;
66 this.events = pool.events;
67 this.externalAuth = pool.externalAuth;
68 this.homogeneous = pool.homogeneous;
69 this.poolAlias = pool.poolAlias;
70 this.poolIncrement = pool.poolIncrement;
71 this.poolMax = pool.poolMax;
72 this.poolMaxPerShard = pool.poolMaxPerShard;
73 this.poolMin = pool.poolMin;
74 this.poolPingInterval = pool.poolPingInterval;
75 this.poolPingTimeout = pool.poolPingTimeout;
76 this.poolTimeout = pool.poolTimeout;
77 this.queueMax = pool.queueMax;
78 this.queueTimeout = pool.queueTimeout;
79 this.sodaMetaDataCache = pool.sodaMetaDataCache;
80 this.stmtCacheSize = pool.stmtCacheSize;
81 this.user = pool.user;
82 this.threadPoolSize = process.env.UV_THREADPOOL_SIZE;
83 this.thin = settings.thin;
84 }
85
86 //---------------------------------------------------------------------------
87 // logStatistics()
88 //
89 // To print the statistics metrics of the pool
90 //---------------------------------------------------------------------------
91 logStatistics() {
92 console.log('\nDriver:');
93 console.log('...thin mode:', this.thin);
94 console.log('Pool statistics:');
95 console.log('...gathered at:', new Date(this.gatheredDate).toISOString());
96 console.log('...up time (milliseconds):', this.upTime);
97 console.log('...up time from last reset (milliseconds)',
98 this.upTimeSinceReset);
99 console.log('...connection requests:', this.connectionRequests);
100 console.log('...requests enqueued:', this.requestsEnqueued);
101 console.log('...requests dequeued:', this.requestsDequeued);
102 console.log('...requests failed:', this.failedRequests);
103 console.log('...requests exceeding queueMax:', this.rejectedRequests);
104 console.log('...requests exceeding queueTimeout:', this.requestTimeouts);
105 console.log('...current queue length:', this.currentQueueLength);
106 console.log('...maximum queue length:', this.maximumQueueLength);
107 console.log('...sum of time in queue (milliseconds):', this.timeInQueue);
108 console.log('...minimum time in queue (milliseconds):',
109 this.minimumTimeInQueue);
110 console.log('...maximum time in queue (milliseconds):',
111 this.maximumTimeInQueue);
112 console.log('...average time in queue (milliseconds):',
113 this.averageTimeInQueue);
114 console.log('...pool connections in use:', this.connectionsInUse);
115 console.log('...pool connections open:', this.connectionsOpen);
116 console.log('Pool attributes:');
117 console.log('...connectString:', this.connectString);
118 console.log('...edition:', this.edition);
119 console.log('...events:', this.events);
120 console.log('...externalAuth:', this.externalAuth);
121 console.log('...homogeneous:', this.homogeneous);
122 console.log('...poolAlias:', this.poolAlias);
123 console.log('...poolIncrement:', this.poolIncrement);
124 console.log('...poolMax:', this.poolMax);
125 console.log('...poolMaxPerShard:', this.poolMaxPerShard);
126 console.log('...poolMin:', this.poolMin);
127 console.log('...poolPingInterval (seconds):', this.poolPingInterval);
128 console.log('...poolPingTimeout (milliseconds):', this.poolPingTimeout);
129 console.log('...poolTimeout (seconds):', this.poolTimeout);
130 console.log('...queueMax:', this.queueMax);
131 console.log('...queueTimeout (milliseconds):', this.queueTimeout);
132 console.log('...sessionCallback:', this.sessionCallback);
133 console.log('...sodaMetaDataCache:', this.sodaMetaDataCache);
134 console.log('...stmtCacheSize:', this.stmtCacheSize);
135 console.log('...user:', this.user);
136 console.log('Related environment variables:');
137 console.log('...UV_THREADPOOL_SIZE:', this.threadPoolSize);
138 }
139}
140
141module.exports = PoolStatistics;