web_plsql 0.18.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -9
- package/package.json +17 -7
- package/src/admin/client/charts.ts +598 -0
- package/src/admin/client/main.js +3 -0
- package/src/admin/client/tailwind.css +41 -0
- package/src/admin/favicon.svg +3 -0
- package/src/admin/index.html +529 -0
- package/src/admin/js/api.ts +170 -0
- package/src/admin/js/app.ts +614 -0
- package/src/admin/js/eslint.config.js +74 -0
- package/src/admin/js/schemas.ts +215 -0
- package/src/admin/js/templates/config.ts +147 -0
- package/src/admin/js/templates/errorRow.ts +21 -0
- package/src/admin/js/templates/index.ts +4 -0
- package/src/admin/js/templates/poolCard.ts +61 -0
- package/src/admin/js/templates/traceRow.ts +24 -0
- package/src/admin/js/tsconfig.json +24 -0
- package/src/admin/js/types.ts +336 -0
- package/src/admin/js/ui/components.ts +44 -0
- package/src/admin/js/ui/table.ts +173 -0
- package/src/admin/js/ui/theme.ts +93 -0
- package/src/admin/js/ui/views.ts +427 -0
- package/src/admin/js/util/format.ts +46 -0
- package/src/admin/js/util/metrics.ts +24 -0
- package/src/admin/lib/chart.bundle.css +1 -0
- package/src/admin/lib/chart.bundle.js +146 -0
- package/src/admin/style.css +1437 -0
- package/src/bin/load-test.js +202 -0
- package/src/handler/handlerAdmin.js +293 -0
- package/src/handler/plsql/cgi.js +1 -1
- package/src/handler/plsql/errorPage.js +31 -6
- package/src/handler/plsql/handlerPlSql.js +32 -6
- package/src/handler/plsql/owaPageStream.js +93 -0
- package/src/handler/plsql/parsePage.js +7 -3
- package/src/handler/plsql/procedure.js +221 -105
- package/src/handler/plsql/procedureNamed.js +34 -49
- package/src/handler/plsql/procedureSanitize.js +120 -45
- package/src/handler/plsql/procedureVariable.js +4 -2
- package/src/handler/plsql/request.js +8 -3
- package/src/handler/plsql/sendResponse.js +43 -5
- package/src/index.js +0 -1
- package/src/server/adminContext.js +23 -0
- package/src/server/config.js +1 -0
- package/src/server/server.js +130 -9
- package/src/types.js +7 -1
- package/src/util/cache.js +123 -0
- package/src/util/jsonLogger.js +47 -0
- package/src/util/shutdown.js +6 -2
- package/src/util/statsManager.js +368 -0
- package/src/util/trace.js +7 -6
- package/src/util/traceManager.js +68 -0
- package/src/version.js +1 -1
- package/types/admin/js/schemas.d.ts +384 -0
- package/types/admin/js/types.d.ts +312 -0
- package/types/handler/handlerAdmin.d.ts +79 -0
- package/types/handler/plsql/errorPage.d.ts +1 -0
- package/types/handler/plsql/handlerPlSql.d.ts +6 -1
- package/types/handler/plsql/owaPageStream.d.ts +28 -0
- package/types/handler/plsql/procedure.d.ts +4 -1
- package/types/handler/plsql/procedureNamed.d.ts +2 -5
- package/types/handler/plsql/procedureSanitize.d.ts +2 -5
- package/types/handler/plsql/procedureVariable.d.ts +1 -1
- package/types/handler/plsql/request.d.ts +3 -1
- package/types/handler/plsql/sendResponse.d.ts +1 -1
- package/types/index.d.ts +0 -1
- package/types/server/adminContext.d.ts +17 -0
- package/types/server/server.d.ts +5 -0
- package/types/types.d.ts +19 -1
- package/types/util/cache.d.ts +69 -0
- package/types/util/jsonLogger.d.ts +45 -0
- package/types/util/statsManager.d.ts +395 -0
- package/types/util/traceManager.d.ts +35 -0
- package/src/handler/handlerMetrics.js +0 -68
- package/types/handler/handlerMetrics.d.ts +0 -25
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} StatsConfig
|
|
3
|
+
* @property {number} intervalMs - Duration of each statistical bucket (default: 5000ms).
|
|
4
|
+
* @property {number} maxHistoryPoints - Number of buckets to keep in the ring buffer (default: 200).
|
|
5
|
+
* @property {boolean} sampleSystem - Whether to automatically sample CPU/Memory (default: true).
|
|
6
|
+
* @property {boolean} samplePools - Whether to automatically sample Oracle pool utilization (default: true).
|
|
7
|
+
* @property {number} percentilePrecision - Max number of samples per bucket for P95/P99 calculation (default: 1000).
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {object} CacheStats
|
|
11
|
+
* @property {number} size - Number of entries.
|
|
12
|
+
* @property {number} hits - Number of hits.
|
|
13
|
+
* @property {number} misses - Number of misses.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} PoolCacheSnapshot
|
|
17
|
+
* @property {CacheStats} procedureName - Procedure name cache stats.
|
|
18
|
+
* @property {CacheStats} argument - Argument cache stats.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {object} PoolSnapshot
|
|
22
|
+
* @property {string} name - The pool name.
|
|
23
|
+
* @property {number} connectionsInUse - Number of active connections.
|
|
24
|
+
* @property {number} connectionsOpen - Number of open connections.
|
|
25
|
+
* @property {PoolCacheSnapshot} [cache] - Cache statistics.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} Bucket
|
|
29
|
+
* @property {number} timestamp - End time of the bucket.
|
|
30
|
+
* @property {number} requests - Number of requests.
|
|
31
|
+
* @property {number} errors - Number of errors.
|
|
32
|
+
* @property {number} durationMin - Minimum duration.
|
|
33
|
+
* @property {number} durationMax - Maximum duration.
|
|
34
|
+
* @property {number} durationAvg - Average duration.
|
|
35
|
+
* @property {number} durationP95 - 95th percentile duration.
|
|
36
|
+
* @property {number} durationP99 - 99th percentile duration.
|
|
37
|
+
* @property {object} system - System metrics.
|
|
38
|
+
* @property {number} system.cpu - CPU usage percentage.
|
|
39
|
+
* @property {number} system.heapUsed - Heap used in bytes.
|
|
40
|
+
* @property {number} system.heapTotal - Heap total in bytes.
|
|
41
|
+
* @property {number} system.rss - RSS in bytes.
|
|
42
|
+
* @property {number} system.external - External memory in bytes.
|
|
43
|
+
* @property {PoolSnapshot[]} pools - Pool utilization snapshots.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {object} CurrentBucket
|
|
47
|
+
* @property {number} count - Number of requests.
|
|
48
|
+
* @property {number} errors - Number of errors.
|
|
49
|
+
* @property {number} durationSum - Sum of durations.
|
|
50
|
+
* @property {number} durationMin - Minimum duration.
|
|
51
|
+
* @property {number} durationMax - Maximum duration.
|
|
52
|
+
* @property {number[]} durations - List of durations for percentile calculation.
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {object} MemoryLifetime
|
|
56
|
+
* @property {number} heapUsedMax - Max heap used.
|
|
57
|
+
* @property {number} heapTotalMax - Max heap total.
|
|
58
|
+
* @property {number} rssMax - Max RSS.
|
|
59
|
+
* @property {number} externalMax - Max external.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* @typedef {object} LifetimeStats
|
|
63
|
+
* @property {number} totalRequests - Total requests.
|
|
64
|
+
* @property {number} totalErrors - Total errors.
|
|
65
|
+
* @property {number} minDuration - Min duration.
|
|
66
|
+
* @property {number} maxDuration - Max duration.
|
|
67
|
+
* @property {number} totalDuration - Total duration.
|
|
68
|
+
* @property {number} maxRequestsPerSecond - Max requests per second.
|
|
69
|
+
* @property {MemoryLifetime} memory - Memory extremes.
|
|
70
|
+
* @property {object} cpu - CPU extremes.
|
|
71
|
+
* @property {number} cpu.max - Max CPU.
|
|
72
|
+
* @property {number} cpu.userMax - Max user CPU.
|
|
73
|
+
* @property {number} cpu.systemMax - Max system CPU.
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* @typedef {object} StatsSummary
|
|
77
|
+
* @property {Date} startTime - Server start time.
|
|
78
|
+
* @property {number} totalRequests - Total requests handled.
|
|
79
|
+
* @property {number} totalErrors - Total errors encountered.
|
|
80
|
+
* @property {number} avgResponseTime - Lifetime average response time.
|
|
81
|
+
* @property {number} minResponseTime - Lifetime minimum response time.
|
|
82
|
+
* @property {number} maxResponseTime - Lifetime maximum response time.
|
|
83
|
+
* @property {number} maxRequestsPerSecond - Lifetime maximum requests per second.
|
|
84
|
+
* @property {MemoryLifetime} maxMemory - Lifetime memory extremes.
|
|
85
|
+
* @property {object} cpu - CPU extremes.
|
|
86
|
+
* @property {number} cpu.max - Max CPU usage percentage.
|
|
87
|
+
* @property {number} cpu.userMax - Max user CPU usage in microseconds.
|
|
88
|
+
* @property {number} cpu.systemMax - Max system CPU usage in microseconds.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* Manager for statistical data collection and temporal bucketing.
|
|
92
|
+
*/
|
|
93
|
+
export class StatsManager {
|
|
94
|
+
/**
|
|
95
|
+
* @param {Partial<StatsConfig>} config - Configuration.
|
|
96
|
+
*/
|
|
97
|
+
constructor(config?: Partial<StatsConfig>);
|
|
98
|
+
/** @type {StatsConfig} */
|
|
99
|
+
config: StatsConfig;
|
|
100
|
+
startTime: Date;
|
|
101
|
+
/** @type {Bucket[]} */
|
|
102
|
+
history: Bucket[];
|
|
103
|
+
/** @type {LifetimeStats} */
|
|
104
|
+
lifetime: LifetimeStats;
|
|
105
|
+
/** @type {CurrentBucket} */
|
|
106
|
+
_currentBucket: CurrentBucket;
|
|
107
|
+
_lastCpuTimes: {
|
|
108
|
+
user: number;
|
|
109
|
+
nice: number;
|
|
110
|
+
sys: number;
|
|
111
|
+
idle: number;
|
|
112
|
+
irq: number;
|
|
113
|
+
total: number;
|
|
114
|
+
};
|
|
115
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
116
|
+
_timer: ReturnType<typeof setTimeout> | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Reset the current bucket accumulator.
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
private _resetBucket;
|
|
122
|
+
/**
|
|
123
|
+
* Record a request event.
|
|
124
|
+
* @param {number} duration - Duration in milliseconds.
|
|
125
|
+
* @param {boolean} isError - Whether the request was an error.
|
|
126
|
+
*/
|
|
127
|
+
recordRequest(duration: number, isError?: boolean): void;
|
|
128
|
+
/**
|
|
129
|
+
* Get system CPU times.
|
|
130
|
+
* @private
|
|
131
|
+
* @returns {{user: number, nice: number, sys: number, idle: number, irq: number, total: number}} System CPU times.
|
|
132
|
+
*/
|
|
133
|
+
private _getSystemCpuTimes;
|
|
134
|
+
/**
|
|
135
|
+
* Calculate CPU usage percentage since last call.
|
|
136
|
+
* @private
|
|
137
|
+
* @returns {number} CPU usage percentage (0-100).
|
|
138
|
+
*/
|
|
139
|
+
private _calculateCpuUsage;
|
|
140
|
+
/**
|
|
141
|
+
* Rotate the current bucket into history and start a new one.
|
|
142
|
+
* @param {PoolSnapshot[]} [poolSnapshots] - Optional pool snapshots to include.
|
|
143
|
+
*/
|
|
144
|
+
rotateBucket(poolSnapshots?: PoolSnapshot[]): void;
|
|
145
|
+
/**
|
|
146
|
+
* Stop the background timer.
|
|
147
|
+
*/
|
|
148
|
+
stop(): void;
|
|
149
|
+
/**
|
|
150
|
+
* Get lifetime summary.
|
|
151
|
+
* @returns {StatsSummary} Summary.
|
|
152
|
+
*/
|
|
153
|
+
getSummary(): StatsSummary;
|
|
154
|
+
/**
|
|
155
|
+
* Get history buffer.
|
|
156
|
+
* @returns {Bucket[]} The history buffer.
|
|
157
|
+
*/
|
|
158
|
+
getHistory(): Bucket[];
|
|
159
|
+
}
|
|
160
|
+
export type StatsConfig = {
|
|
161
|
+
/**
|
|
162
|
+
* - Duration of each statistical bucket (default: 5000ms).
|
|
163
|
+
*/
|
|
164
|
+
intervalMs: number;
|
|
165
|
+
/**
|
|
166
|
+
* - Number of buckets to keep in the ring buffer (default: 200).
|
|
167
|
+
*/
|
|
168
|
+
maxHistoryPoints: number;
|
|
169
|
+
/**
|
|
170
|
+
* - Whether to automatically sample CPU/Memory (default: true).
|
|
171
|
+
*/
|
|
172
|
+
sampleSystem: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* - Whether to automatically sample Oracle pool utilization (default: true).
|
|
175
|
+
*/
|
|
176
|
+
samplePools: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* - Max number of samples per bucket for P95/P99 calculation (default: 1000).
|
|
179
|
+
*/
|
|
180
|
+
percentilePrecision: number;
|
|
181
|
+
};
|
|
182
|
+
export type CacheStats = {
|
|
183
|
+
/**
|
|
184
|
+
* - Number of entries.
|
|
185
|
+
*/
|
|
186
|
+
size: number;
|
|
187
|
+
/**
|
|
188
|
+
* - Number of hits.
|
|
189
|
+
*/
|
|
190
|
+
hits: number;
|
|
191
|
+
/**
|
|
192
|
+
* - Number of misses.
|
|
193
|
+
*/
|
|
194
|
+
misses: number;
|
|
195
|
+
};
|
|
196
|
+
export type PoolCacheSnapshot = {
|
|
197
|
+
/**
|
|
198
|
+
* - Procedure name cache stats.
|
|
199
|
+
*/
|
|
200
|
+
procedureName: CacheStats;
|
|
201
|
+
/**
|
|
202
|
+
* - Argument cache stats.
|
|
203
|
+
*/
|
|
204
|
+
argument: CacheStats;
|
|
205
|
+
};
|
|
206
|
+
export type PoolSnapshot = {
|
|
207
|
+
/**
|
|
208
|
+
* - The pool name.
|
|
209
|
+
*/
|
|
210
|
+
name: string;
|
|
211
|
+
/**
|
|
212
|
+
* - Number of active connections.
|
|
213
|
+
*/
|
|
214
|
+
connectionsInUse: number;
|
|
215
|
+
/**
|
|
216
|
+
* - Number of open connections.
|
|
217
|
+
*/
|
|
218
|
+
connectionsOpen: number;
|
|
219
|
+
/**
|
|
220
|
+
* - Cache statistics.
|
|
221
|
+
*/
|
|
222
|
+
cache?: PoolCacheSnapshot;
|
|
223
|
+
};
|
|
224
|
+
export type Bucket = {
|
|
225
|
+
/**
|
|
226
|
+
* - End time of the bucket.
|
|
227
|
+
*/
|
|
228
|
+
timestamp: number;
|
|
229
|
+
/**
|
|
230
|
+
* - Number of requests.
|
|
231
|
+
*/
|
|
232
|
+
requests: number;
|
|
233
|
+
/**
|
|
234
|
+
* - Number of errors.
|
|
235
|
+
*/
|
|
236
|
+
errors: number;
|
|
237
|
+
/**
|
|
238
|
+
* - Minimum duration.
|
|
239
|
+
*/
|
|
240
|
+
durationMin: number;
|
|
241
|
+
/**
|
|
242
|
+
* - Maximum duration.
|
|
243
|
+
*/
|
|
244
|
+
durationMax: number;
|
|
245
|
+
/**
|
|
246
|
+
* - Average duration.
|
|
247
|
+
*/
|
|
248
|
+
durationAvg: number;
|
|
249
|
+
/**
|
|
250
|
+
* - 95th percentile duration.
|
|
251
|
+
*/
|
|
252
|
+
durationP95: number;
|
|
253
|
+
/**
|
|
254
|
+
* - 99th percentile duration.
|
|
255
|
+
*/
|
|
256
|
+
durationP99: number;
|
|
257
|
+
/**
|
|
258
|
+
* - System metrics.
|
|
259
|
+
*/
|
|
260
|
+
system: {
|
|
261
|
+
cpu: number;
|
|
262
|
+
heapUsed: number;
|
|
263
|
+
heapTotal: number;
|
|
264
|
+
rss: number;
|
|
265
|
+
external: number;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* - Pool utilization snapshots.
|
|
269
|
+
*/
|
|
270
|
+
pools: PoolSnapshot[];
|
|
271
|
+
};
|
|
272
|
+
export type CurrentBucket = {
|
|
273
|
+
/**
|
|
274
|
+
* - Number of requests.
|
|
275
|
+
*/
|
|
276
|
+
count: number;
|
|
277
|
+
/**
|
|
278
|
+
* - Number of errors.
|
|
279
|
+
*/
|
|
280
|
+
errors: number;
|
|
281
|
+
/**
|
|
282
|
+
* - Sum of durations.
|
|
283
|
+
*/
|
|
284
|
+
durationSum: number;
|
|
285
|
+
/**
|
|
286
|
+
* - Minimum duration.
|
|
287
|
+
*/
|
|
288
|
+
durationMin: number;
|
|
289
|
+
/**
|
|
290
|
+
* - Maximum duration.
|
|
291
|
+
*/
|
|
292
|
+
durationMax: number;
|
|
293
|
+
/**
|
|
294
|
+
* - List of durations for percentile calculation.
|
|
295
|
+
*/
|
|
296
|
+
durations: number[];
|
|
297
|
+
};
|
|
298
|
+
export type MemoryLifetime = {
|
|
299
|
+
/**
|
|
300
|
+
* - Max heap used.
|
|
301
|
+
*/
|
|
302
|
+
heapUsedMax: number;
|
|
303
|
+
/**
|
|
304
|
+
* - Max heap total.
|
|
305
|
+
*/
|
|
306
|
+
heapTotalMax: number;
|
|
307
|
+
/**
|
|
308
|
+
* - Max RSS.
|
|
309
|
+
*/
|
|
310
|
+
rssMax: number;
|
|
311
|
+
/**
|
|
312
|
+
* - Max external.
|
|
313
|
+
*/
|
|
314
|
+
externalMax: number;
|
|
315
|
+
};
|
|
316
|
+
export type LifetimeStats = {
|
|
317
|
+
/**
|
|
318
|
+
* - Total requests.
|
|
319
|
+
*/
|
|
320
|
+
totalRequests: number;
|
|
321
|
+
/**
|
|
322
|
+
* - Total errors.
|
|
323
|
+
*/
|
|
324
|
+
totalErrors: number;
|
|
325
|
+
/**
|
|
326
|
+
* - Min duration.
|
|
327
|
+
*/
|
|
328
|
+
minDuration: number;
|
|
329
|
+
/**
|
|
330
|
+
* - Max duration.
|
|
331
|
+
*/
|
|
332
|
+
maxDuration: number;
|
|
333
|
+
/**
|
|
334
|
+
* - Total duration.
|
|
335
|
+
*/
|
|
336
|
+
totalDuration: number;
|
|
337
|
+
/**
|
|
338
|
+
* - Max requests per second.
|
|
339
|
+
*/
|
|
340
|
+
maxRequestsPerSecond: number;
|
|
341
|
+
/**
|
|
342
|
+
* - Memory extremes.
|
|
343
|
+
*/
|
|
344
|
+
memory: MemoryLifetime;
|
|
345
|
+
/**
|
|
346
|
+
* - CPU extremes.
|
|
347
|
+
*/
|
|
348
|
+
cpu: {
|
|
349
|
+
max: number;
|
|
350
|
+
userMax: number;
|
|
351
|
+
systemMax: number;
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
export type StatsSummary = {
|
|
355
|
+
/**
|
|
356
|
+
* - Server start time.
|
|
357
|
+
*/
|
|
358
|
+
startTime: Date;
|
|
359
|
+
/**
|
|
360
|
+
* - Total requests handled.
|
|
361
|
+
*/
|
|
362
|
+
totalRequests: number;
|
|
363
|
+
/**
|
|
364
|
+
* - Total errors encountered.
|
|
365
|
+
*/
|
|
366
|
+
totalErrors: number;
|
|
367
|
+
/**
|
|
368
|
+
* - Lifetime average response time.
|
|
369
|
+
*/
|
|
370
|
+
avgResponseTime: number;
|
|
371
|
+
/**
|
|
372
|
+
* - Lifetime minimum response time.
|
|
373
|
+
*/
|
|
374
|
+
minResponseTime: number;
|
|
375
|
+
/**
|
|
376
|
+
* - Lifetime maximum response time.
|
|
377
|
+
*/
|
|
378
|
+
maxResponseTime: number;
|
|
379
|
+
/**
|
|
380
|
+
* - Lifetime maximum requests per second.
|
|
381
|
+
*/
|
|
382
|
+
maxRequestsPerSecond: number;
|
|
383
|
+
/**
|
|
384
|
+
* - Lifetime memory extremes.
|
|
385
|
+
*/
|
|
386
|
+
maxMemory: MemoryLifetime;
|
|
387
|
+
/**
|
|
388
|
+
* - CPU extremes.
|
|
389
|
+
*/
|
|
390
|
+
cpu: {
|
|
391
|
+
max: number;
|
|
392
|
+
userMax: number;
|
|
393
|
+
systemMax: number;
|
|
394
|
+
};
|
|
395
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const traceManager: TraceManager;
|
|
2
|
+
export type TraceEntry = import("../admin/js/types.js").TraceEntry;
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('../admin/js/types.js').TraceEntry} TraceEntry
|
|
5
|
+
*/
|
|
6
|
+
declare class TraceManager {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
filename: string;
|
|
9
|
+
maxEntries: number;
|
|
10
|
+
/**
|
|
11
|
+
* Toggle tracing
|
|
12
|
+
* @param {boolean} enabled - New state
|
|
13
|
+
*/
|
|
14
|
+
setEnabled(enabled: boolean): void;
|
|
15
|
+
/**
|
|
16
|
+
* Is tracing enabled?
|
|
17
|
+
* @returns {boolean} - The state
|
|
18
|
+
*/
|
|
19
|
+
isEnabled(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Add a trace entry
|
|
22
|
+
* @param {object} entry - The trace entry
|
|
23
|
+
*/
|
|
24
|
+
addTrace(entry: object): void;
|
|
25
|
+
/**
|
|
26
|
+
* Clear all traces
|
|
27
|
+
*/
|
|
28
|
+
clear(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get the full path to the trace file
|
|
31
|
+
* @returns {string} - The path
|
|
32
|
+
*/
|
|
33
|
+
getFilePath(): string;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import debugModule from 'debug';
|
|
2
|
-
const debug = debugModule('webplsql:handlerMetrics');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {import('express').RequestHandler} RequestHandler
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {object} metricsType
|
|
10
|
-
* @property {Date} started - When was the server started.
|
|
11
|
-
* @property {number} totalRequests - Total number of requests.
|
|
12
|
-
* @property {number} totalRequestDuration - Total amount of time in ms in request.
|
|
13
|
-
* @property {number} minRequestDuration - Min amount of time in ms in request.
|
|
14
|
-
* @property {number} maxRequestDuration - Max amount of time in ms in request.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Convert hrtime to ms.
|
|
19
|
-
* @param {[number, number]} hrtime - Time
|
|
20
|
-
* @returns {number} Millisecoinds.
|
|
21
|
-
*/
|
|
22
|
-
const hrtime2ms = (hrtime) => hrtime[0] * 1000 + hrtime[1] / 1_000_000;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* metrics initializer.
|
|
26
|
-
* @returns {metricsType} The metrics.
|
|
27
|
-
*/
|
|
28
|
-
export const initMetrics = () => {
|
|
29
|
-
return {
|
|
30
|
-
started: new Date(),
|
|
31
|
-
totalRequests: 0,
|
|
32
|
-
totalRequestDuration: 0,
|
|
33
|
-
minRequestDuration: -1,
|
|
34
|
-
maxRequestDuration: -1,
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The metrics handler.
|
|
40
|
-
* @param {metricsType} metrics - the nmetrics.
|
|
41
|
-
* @returns {RequestHandler} - Request handler.
|
|
42
|
-
*/
|
|
43
|
-
export const handlerMetrics = (metrics) => {
|
|
44
|
-
debug('register');
|
|
45
|
-
|
|
46
|
-
return (req, res, next) => {
|
|
47
|
-
metrics.totalRequests++;
|
|
48
|
-
|
|
49
|
-
const start = hrtime2ms(process.hrtime());
|
|
50
|
-
res.on('finish', () => {
|
|
51
|
-
const duration = hrtime2ms(process.hrtime()) - start;
|
|
52
|
-
|
|
53
|
-
metrics.totalRequestDuration += duration;
|
|
54
|
-
if (metrics.minRequestDuration < 0 || duration < metrics.minRequestDuration) {
|
|
55
|
-
metrics.minRequestDuration = duration;
|
|
56
|
-
}
|
|
57
|
-
if (metrics.maxRequestDuration < 0 || duration > metrics.maxRequestDuration) {
|
|
58
|
-
metrics.maxRequestDuration = duration;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (debug.enabled) {
|
|
62
|
-
debug(`Request to ${req.params?.name} ${req.url} took ${duration.toFixed(3)}ms`);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
next();
|
|
67
|
-
};
|
|
68
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export function initMetrics(): metricsType;
|
|
2
|
-
export function handlerMetrics(metrics: metricsType): RequestHandler;
|
|
3
|
-
export type RequestHandler = import("express").RequestHandler;
|
|
4
|
-
export type metricsType = {
|
|
5
|
-
/**
|
|
6
|
-
* - When was the server started.
|
|
7
|
-
*/
|
|
8
|
-
started: Date;
|
|
9
|
-
/**
|
|
10
|
-
* - Total number of requests.
|
|
11
|
-
*/
|
|
12
|
-
totalRequests: number;
|
|
13
|
-
/**
|
|
14
|
-
* - Total amount of time in ms in request.
|
|
15
|
-
*/
|
|
16
|
-
totalRequestDuration: number;
|
|
17
|
-
/**
|
|
18
|
-
* - Min amount of time in ms in request.
|
|
19
|
-
*/
|
|
20
|
-
minRequestDuration: number;
|
|
21
|
-
/**
|
|
22
|
-
* - Max amount of time in ms in request.
|
|
23
|
-
*/
|
|
24
|
-
maxRequestDuration: number;
|
|
25
|
-
};
|