@nsshunt/stsappframework 3.1.235 → 3.1.237
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/dist/stsappframework.mjs +1979 -0
- package/dist/stsappframework.mjs.map +1 -0
- package/dist/stsappframework.umd.js +1954 -0
- package/dist/stsappframework.umd.js.map +1 -0
- package/package.json +21 -7
- package/.github/dependabot.yml +0 -13
- package/.github/workflows/npm-publish.yml +0 -46
- package/.gitignore copy +0 -108
- package/build.sh +0 -36
- package/dist/index.js +0 -30
- package/eslint.config.mjs +0 -55
- package/jest/setEnvVars.js +0 -19
- package/keys/server.cert +0 -21
- package/keys/server.key +0 -28
- package/local-redis-stack.conf +0 -2
- package/run-grpc-client.sh +0 -2
- package/run-grpc-server.sh +0 -2
- package/run1.sh +0 -20
- package/run2.sh +0 -20
- package/run3.sh +0 -20
- package/runc1.sh +0 -19
- package/runc2.sh +0 -19
- package/runkafka.sh +0 -19
- package/runkafkaconsume01.sh +0 -21
- package/runkafkaconsume02.sh +0 -21
- package/runpromise.sh +0 -5
- package/runredis.sh +0 -5
- package/runredis1.sh +0 -4
- package/runredis2.sh +0 -24
- package/runredis3.sh +0 -4
- package/runtest1.sh +0 -19
- package/runtest2.sh +0 -19
- package/runtest_ipc_legacy.sh +0 -19
- package/runtest_ipcex.sh +0 -19
- package/runtest_redis.sh +0 -19
- package/runtest_ww.sh +0 -19
- package/src/commonTypes.ts +0 -374
- package/src/controller/stscontrollerbase.ts +0 -14
- package/src/controller/stslatencycontroller.ts +0 -26
- package/src/index.ts +0 -13
- package/src/logger/stsTransportLoggerWinston.ts +0 -24
- package/src/logger/stsTransportWinston.ts +0 -48
- package/src/middleware/serverNetworkMiddleware.ts +0 -243
- package/src/network.ts +0 -36
- package/src/process/masterprocessbase.ts +0 -674
- package/src/process/processbase.ts +0 -483
- package/src/process/serverprocessbase.ts +0 -455
- package/src/process/singleprocessbase.ts +0 -63
- package/src/process/workerprocessbase.ts +0 -224
- package/src/publishertransports/publishTransportUtils.ts +0 -53
- package/src/route/stslatencyroute.ts +0 -15
- package/src/route/stsrouterbase.ts +0 -21
- package/src/stsexpressserver.ts +0 -137
- package/src/validation/errors.ts +0 -6
- package/src/vitesttesting/appConfig.ts +0 -111
- package/src/vitesttesting/appSingleWSS.ts +0 -142
- package/src/vitesttesting/server.ts +0 -17
- package/src/vitesttesting/singleservertest.test.ts +0 -352
- package/src/vitesttesting/wsevents.ts +0 -44
- package/tsconfig.json +0 -42
- package/vite.config.ts +0 -19
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
import pidusage from 'pidusage'
|
|
3
|
-
import { memoryUsage } from 'process'
|
|
4
|
-
import cluster from 'node:cluster'
|
|
5
|
-
import si from 'systeminformation' // https://systeminformation.io/
|
|
6
|
-
import { GetFirstNetworkInterface } from './../network'
|
|
7
|
-
|
|
8
|
-
import chalk from 'chalk';
|
|
9
|
-
|
|
10
|
-
import { Gauge, InstrumentBaseTelemetry, InstrumentGaugeTelemetry, InstrumentObjectTelemetry, InstrumentLogTelemetry } from '@nsshunt/stsobservability'
|
|
11
|
-
|
|
12
|
-
import { IDBAccessLayer, accessLayerType, DBAccessLayerManager, IDBAccessLayerEvents } from '@nsshunt/stsdatamanagement'
|
|
13
|
-
|
|
14
|
-
import { goptions } from '@nsshunt/stsconfig'
|
|
15
|
-
|
|
16
|
-
import { JSONObject } from '@nsshunt/stsutils'
|
|
17
|
-
import { StatusCodes } from 'http-status-codes'
|
|
18
|
-
|
|
19
|
-
import { PublishInstrumentController, IPublishInstrumentControllerOptions, InstrumentDefinitions,
|
|
20
|
-
TransportType, IPublishTransportRESTServerOptions, GetInstruments } from '@nsshunt/stsobservability'
|
|
21
|
-
|
|
22
|
-
import { STSDefaultClientToServerEvents, STSDefaultServerToClientEvents } from '@nsshunt/stssocketioutils'
|
|
23
|
-
import os from 'os';
|
|
24
|
-
|
|
25
|
-
import { IProcessBase, CreateServiceProcessContext, ProcessOptions, IProcessBaseEvents } from './../commonTypes'
|
|
26
|
-
|
|
27
|
-
import { TinyEmitter } from 'tiny-emitter';
|
|
28
|
-
|
|
29
|
-
import { ISocketIoServerHelper } from '@nsshunt/stssocketioutils'
|
|
30
|
-
|
|
31
|
-
export abstract class ProcessBase extends TinyEmitter implements IProcessBase
|
|
32
|
-
{
|
|
33
|
-
#options: ProcessOptions;
|
|
34
|
-
#instrumentController: PublishInstrumentController | null = null;
|
|
35
|
-
#systemInformationInterval: NodeJS.Timeout | null = null;
|
|
36
|
-
#socketIoServerHelper: ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null = null;
|
|
37
|
-
#accessLayer: IDBAccessLayer | null = null;
|
|
38
|
-
//#redisMessageHandler: RedisMessageHandler | null = null;
|
|
39
|
-
|
|
40
|
-
constructor(options: ProcessOptions) {
|
|
41
|
-
super();
|
|
42
|
-
this.#options = options;
|
|
43
|
-
|
|
44
|
-
if (options.serviceName) {
|
|
45
|
-
this.options.serviceProcessContext = CreateServiceProcessContext(options.serviceName, options.serviceVersion, options.serviceInstanceId,
|
|
46
|
-
os.hostname(), process.pid, options.isMaster ? process.pid : process.ppid)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
#GetFormattedLogMessage(message: string): string {
|
|
51
|
-
let prefix = '';
|
|
52
|
-
let col = null;
|
|
53
|
-
const appName = this.options.serviceName;
|
|
54
|
-
|
|
55
|
-
if (cluster.isPrimary) {
|
|
56
|
-
prefix = 'M';
|
|
57
|
-
col = chalk.bold.cyan;
|
|
58
|
-
} else {
|
|
59
|
-
prefix = 'W';
|
|
60
|
-
col = chalk.green;
|
|
61
|
-
}
|
|
62
|
-
return col(`${prefix}(${process.pid}) [${appName}]: ${message}`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
LogErrorMessage(message: any) {
|
|
66
|
-
this.options.logger.error(this.#GetFormattedLogMessage(message));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
LogInfoMessage(message: any) {
|
|
70
|
-
this.options.logger.info(this.#GetFormattedLogMessage(message));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
LogMessageToLoggerInstrument(message: any) {
|
|
74
|
-
this.UpdateInstrument(Gauge.LOGGER, {
|
|
75
|
-
LogMessage: this.#GetFormattedLogMessage(message)
|
|
76
|
-
} as InstrumentLogTelemetry);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get options(): ProcessOptions {
|
|
80
|
-
return this.#options as ProcessOptions;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get shuttingDown(): boolean {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
SetupInstrumentation()
|
|
88
|
-
{
|
|
89
|
-
if (!this.options.serviceProcessContext) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let publishTransportOptions: IPublishTransportRESTServerOptions | null = null;
|
|
94
|
-
if (goptions.observabilityPublishMode.localeCompare('PROXY') === 0) {
|
|
95
|
-
publishTransportOptions = {
|
|
96
|
-
transportType: TransportType.RESTAPI,
|
|
97
|
-
url: `${goptions.imendpoint}:${goptions.import}${goptions.imapiroot}/publishmessage`,
|
|
98
|
-
// socketPath: '/var/run/sts/stsrest01.sock'
|
|
99
|
-
agentOptions: {
|
|
100
|
-
keepAlive: goptions.keepAlive,
|
|
101
|
-
maxSockets: goptions.maxSockets,
|
|
102
|
-
maxTotalSockets: goptions.maxTotalSockets,
|
|
103
|
-
maxFreeSockets: goptions.maxFreeSockets,
|
|
104
|
-
timeout: goptions.timeout,
|
|
105
|
-
rejectUnauthorized: goptions.isProduction // Allows self signed certs in non production mode(s)
|
|
106
|
-
},
|
|
107
|
-
logger: this.options.publisherLogger
|
|
108
|
-
};
|
|
109
|
-
} else {
|
|
110
|
-
// Currently, now other types are supported
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const httpServer: boolean = (goptions.STSServerType.localeCompare('EXPRESS') === 0) || (goptions.STSServerType.localeCompare('EXPRESS_TLS') === 0);
|
|
115
|
-
|
|
116
|
-
//const fileName = './dist/publishInstrumentsWebWorker.js';
|
|
117
|
-
//const worker = new Worker(fileName);
|
|
118
|
-
|
|
119
|
-
const instrumentControllerOptions: IPublishInstrumentControllerOptions = {
|
|
120
|
-
|
|
121
|
-
processContext: this.options.serviceProcessContext,
|
|
122
|
-
//payloadType: InstrumentPayloadType.service,
|
|
123
|
-
consoleLogging: this.options.consoleLogging,
|
|
124
|
-
instrumentLogging: this.options.instrumentLogging,
|
|
125
|
-
httpServer,
|
|
126
|
-
instrumentationObservationInterval: this.options.instrumentationObservationInterval,
|
|
127
|
-
instrumentationTimeWindow: this.options.instrumentationTimeWindow,
|
|
128
|
-
logger: this.options.publisherLogger,
|
|
129
|
-
publishInterval: this.options.publishInterval,
|
|
130
|
-
publishPostFailInterval: 5000, //@@
|
|
131
|
-
instrumentDefinitions: GetInstruments('service'),
|
|
132
|
-
publishTransportBaseOptions: publishTransportOptions,
|
|
133
|
-
autoStart: true
|
|
134
|
-
/*
|
|
135
|
-
[
|
|
136
|
-
...this.#GetDefaultServiceInstruments(httpServer),
|
|
137
|
-
...this.GetAdditionalInstruments()
|
|
138
|
-
]
|
|
139
|
-
*/
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
this.#instrumentController = new PublishInstrumentController(instrumentControllerOptions);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/*
|
|
146
|
-
#GetDefaultServiceInstruments(httpServer: boolean): InstrumentDefinitions {
|
|
147
|
-
const standardInstruments: InstrumentDefinitions = [
|
|
148
|
-
[ Gauge.TIMER_GAUGE, GaugeTypes.INSTRUMENT_TIMER ],
|
|
149
|
-
[ Gauge.LOGGER, GaugeTypes.INSTRUMENT_LOG, {
|
|
150
|
-
consoleLogging: this.options.consoleLogging,
|
|
151
|
-
instrumentLogging: this.options.instrumentLogging } as InstrumentLogOptions],
|
|
152
|
-
[ Gauge.NETWORK_RX_GAUGE , GaugeTypes.INSTRUMENT_VELOCITY ],
|
|
153
|
-
[ Gauge.NETWORK_TX_GAUGE, GaugeTypes.INSTRUMENT_VELOCITY ],
|
|
154
|
-
[ Gauge.CPU_LOAD_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
|
|
155
|
-
interval: this.options.instrumentationObservationInterval,
|
|
156
|
-
sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
|
|
157
|
-
[ Gauge.OBJECT_GAUGE, GaugeTypes.INSTRUMENT_OBJECT, {
|
|
158
|
-
label:'InstrumentObjectMaster' } as InstrumentObjectOptions]
|
|
159
|
-
];
|
|
160
|
-
|
|
161
|
-
let httpServerInstruments: InstrumentDefinitions = [ ];
|
|
162
|
-
if (httpServer) {
|
|
163
|
-
httpServerInstruments = [
|
|
164
|
-
[ Gauge.REQUEST_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of requests serviced
|
|
165
|
-
[ Gauge.AUTHENTICATION_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests
|
|
166
|
-
[ Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests errors
|
|
167
|
-
[ Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests retries
|
|
168
|
-
|
|
169
|
-
[ Gauge.ACTIVE_REQUEST_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
|
|
170
|
-
interval: this.options.instrumentationObservationInterval,
|
|
171
|
-
sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
|
|
172
|
-
[ Gauge.DURATION_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
|
|
173
|
-
interval: this.options.instrumentationObservationInterval,
|
|
174
|
-
sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
|
|
175
|
-
[ Gauge.DURATION_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
|
|
176
|
-
[ Gauge.CONNECTION_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
|
|
177
|
-
interval: this.options.instrumentationObservationInterval,
|
|
178
|
-
sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
|
|
179
|
-
|
|
180
|
-
[ Gauge.CONNECTION_POOL_TOTAL_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
|
|
181
|
-
[ Gauge.CONNECTION_POOL_IDLE_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
|
|
182
|
-
[ Gauge.CONNECTION_POOL_WAITING_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
|
|
183
|
-
[ Gauge.VELOCITY_GAUGE, GaugeTypes.INSTRUMENT_VELOCITY ], // Requests per second
|
|
184
|
-
[ Gauge.ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
|
|
185
|
-
[ Gauge.RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
|
|
186
|
-
[ Gauge.LATENCY_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
|
|
187
|
-
interval: this.options.instrumentationObservationInterval,
|
|
188
|
-
sampleSize: this.options.instrumentationTimeWindow } as InstrumentGaugeOptions],
|
|
189
|
-
[ Gauge.LATENCY_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
|
|
190
|
-
[ Gauge.CORE_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ]
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
return [
|
|
194
|
-
...standardInstruments,
|
|
195
|
-
...httpServerInstruments
|
|
196
|
-
]
|
|
197
|
-
}
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
GetAdditionalInstruments(): InstrumentDefinitions {
|
|
201
|
-
return [ ];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
CollectAdditionalTelemetry(): void { // eslint-disable @typescript-eslint/no-empty-function
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
ProcessStartup = () => {
|
|
209
|
-
// use this as well
|
|
210
|
-
// performance.eventLoopUtilization([utilization1[, utilization2]])
|
|
211
|
-
// https://nodejs.org/api/perf_hooks.html#perf_hooksmonitoreventloopdelayoptions
|
|
212
|
-
|
|
213
|
-
const ExecuteGetStats = async () => {
|
|
214
|
-
const startTime = performance.now();
|
|
215
|
-
|
|
216
|
-
if (this.#instrumentController) {
|
|
217
|
-
const stats = await pidusage(process.pid);
|
|
218
|
-
let useStatsCpu = stats.cpu;
|
|
219
|
-
if (useStatsCpu < 0.01) {
|
|
220
|
-
useStatsCpu = 0.01; //@@ Endure we record something about 0. 0's are filtered from monitoring tools.
|
|
221
|
-
}
|
|
222
|
-
this.#instrumentController.UpdateInstrument(Gauge.CPU_LOAD_GAUGE, {
|
|
223
|
-
val: useStatsCpu
|
|
224
|
-
} as InstrumentGaugeTelemetry);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
/*
|
|
228
|
-
pidusage(process.pid, (err, stats) => {
|
|
229
|
-
if (this.#instrumentController) {
|
|
230
|
-
let useStatsCpu = stats.cpu;
|
|
231
|
-
if (useStatsCpu < 3) {
|
|
232
|
-
useStatsCpu = 3; //@@ Endure we record something about 0. 0's are filtered from monitoring tools.
|
|
233
|
-
}
|
|
234
|
-
this.#instrumentController.UpdateInstrument(Gauge.CPU_LOAD_GAUGE, {
|
|
235
|
-
val: useStatsCpu
|
|
236
|
-
} as InstrumentGaugeTelemetry);
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
*/
|
|
240
|
-
|
|
241
|
-
// https://nodejs.org/api/process.html#processmemoryusage
|
|
242
|
-
const usage = memoryUsage();
|
|
243
|
-
const telemetry: JSONObject = {
|
|
244
|
-
r: usage.rss,
|
|
245
|
-
t: usage.heapTotal,
|
|
246
|
-
u: usage.heapUsed,
|
|
247
|
-
x: usage.external,
|
|
248
|
-
a: usage.arrayBuffers,
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
this.UpdateInstrument(Gauge.OBJECT_GAUGE, {
|
|
252
|
-
val: telemetry
|
|
253
|
-
} as InstrumentObjectTelemetry);
|
|
254
|
-
|
|
255
|
-
this.CollectAdditionalTelemetry();
|
|
256
|
-
|
|
257
|
-
const totalTime = performance.now() - startTime;
|
|
258
|
-
const nextLoopTime = goptions.systemInformationInterval - totalTime;
|
|
259
|
-
|
|
260
|
-
this.#systemInformationInterval = setTimeout(ExecuteGetStats, nextLoopTime).unref();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
this.#systemInformationInterval = setTimeout(ExecuteGetStats, goptions.systemInformationInterval).unref();
|
|
264
|
-
|
|
265
|
-
if (this.options.useDatabase) {
|
|
266
|
-
// Get the accessLayer to force DB connection test
|
|
267
|
-
const accessLayer = this.accessLayer;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
//@@this.LogInfoMessage(`RedisMessageHandler: redisUrl: [${goptions.imRedisMessageProcessorUrl}]`);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
UpdateInstrument = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry) => {
|
|
274
|
-
if (this.#instrumentController) {
|
|
275
|
-
this.#instrumentController.UpdateInstrument(instrumentName, telemetry);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
ProcessExit = (processExitDelay: number) => {
|
|
280
|
-
if (this.options.processExitOnTerminate && this.options.processExitOnTerminate === true) {
|
|
281
|
-
setTimeout(() => {
|
|
282
|
-
this.LogInfoMessage(`Performing process.exit(0).`);
|
|
283
|
-
process.exit(0);
|
|
284
|
-
}, processExitDelay); // Give the workers time to terminate gracefully
|
|
285
|
-
} else {
|
|
286
|
-
this.LogInfoMessage(`Performing process.exit(0) - Immediate.`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
TerminateInstrumentController = () => {
|
|
291
|
-
if (this.InstrumentController) {
|
|
292
|
-
this.LogInfoMessage(`ProcessBase:TerminateInstrumentController()`);
|
|
293
|
-
setTimeout(() => {
|
|
294
|
-
if (this.InstrumentController) {
|
|
295
|
-
this.InstrumentController.EndPublish();
|
|
296
|
-
}
|
|
297
|
-
}, 100);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
get InstrumentController(): PublishInstrumentController | null {
|
|
302
|
-
return this.#instrumentController;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
InstrumentExists(instrumentName: Gauge): boolean
|
|
306
|
-
{
|
|
307
|
-
if (this.#instrumentController) {
|
|
308
|
-
return this.#instrumentController.InstrumentExists(instrumentName);
|
|
309
|
-
}
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
TerminateUIController = () => {
|
|
314
|
-
if (this.GetUIController() !== null) {
|
|
315
|
-
this.LogInfoMessage('ProcessBase:TerminateUIController(): Destroy the user interface controller.');
|
|
316
|
-
this.GetUIController().DestroyUI();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
async ProcessTerminate(): Promise<void> {
|
|
321
|
-
this.emit('ProcessTerminate');
|
|
322
|
-
|
|
323
|
-
if (this.#systemInformationInterval) {
|
|
324
|
-
clearTimeout(this.#systemInformationInterval);
|
|
325
|
-
}
|
|
326
|
-
this.#systemInformationInterval = null;
|
|
327
|
-
|
|
328
|
-
//@@this.#redisMessageHandler?.Stop();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* UIController (instance of UIController) to manage a console based user interface associated for this node application.
|
|
333
|
-
* @returns UIController instance to manage a console based user interface associated for this node application.
|
|
334
|
-
*/
|
|
335
|
-
GetUIController(): any {
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
get socketIoServerHelper(): ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null
|
|
340
|
-
{
|
|
341
|
-
return this.#socketIoServerHelper;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
set socketIoServerHelper(value: ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null)
|
|
345
|
-
{
|
|
346
|
-
this.#socketIoServerHelper = value;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
#UpdatePGPoolManagerInstrument = (data: any) => {
|
|
350
|
-
this.UpdateInstrument(Gauge.CONNECTION_POOL_TOTAL_GAUGE, {
|
|
351
|
-
val: data.totalCount
|
|
352
|
-
} as InstrumentGaugeTelemetry);
|
|
353
|
-
|
|
354
|
-
this.UpdateInstrument(Gauge.CONNECTION_POOL_IDLE_GAUGE, {
|
|
355
|
-
val: data.idleCount
|
|
356
|
-
} as InstrumentGaugeTelemetry);
|
|
357
|
-
|
|
358
|
-
this.UpdateInstrument(Gauge.CONNECTION_POOL_WAITING_GAUGE, {
|
|
359
|
-
val: data.waitingCount
|
|
360
|
-
} as InstrumentGaugeTelemetry);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
async TerminateDatabase(): Promise<void> {
|
|
364
|
-
if (this.#accessLayer) {
|
|
365
|
-
const logPrefix = `ProcessBase:TerminateDatabase():${process.pid}:`;
|
|
366
|
-
this.LogInfoMessage(`${logPrefix} Ending database connections and pools.`);
|
|
367
|
-
this.#accessLayer.off(IDBAccessLayerEvents.UpdateInstruments, this.#UpdatePGPoolManagerInstrument)
|
|
368
|
-
await this.#accessLayer.EndDatabase();
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
get accessLayer(): IDBAccessLayer | null
|
|
373
|
-
{
|
|
374
|
-
if (this.options.useDatabase) {
|
|
375
|
-
if (this.#accessLayer === null) {
|
|
376
|
-
|
|
377
|
-
this.#accessLayer = new DBAccessLayerManager().CreateAccessLayer({
|
|
378
|
-
accessLayerType: accessLayerType.postgresql,
|
|
379
|
-
accessLayerOptions: {
|
|
380
|
-
logger: this.options.logger,
|
|
381
|
-
usedefaultdb: false
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
this.#accessLayer.on(IDBAccessLayerEvents.UpdateInstruments, this.#UpdatePGPoolManagerInstrument);
|
|
386
|
-
|
|
387
|
-
(async () => {
|
|
388
|
-
try {
|
|
389
|
-
const retVal = await (this.accessLayer as IDBAccessLayer).GetResourceCount();
|
|
390
|
-
if (retVal.status !== StatusCodes.OK) {
|
|
391
|
-
this.LogInfoMessage(chalk.red(`Unable to get resources from the database. Is the database running? [${JSON.stringify(retVal)}]`));
|
|
392
|
-
} else {
|
|
393
|
-
this.LogInfoMessage(chalk.green(`Database connection successful. Resources: [${retVal.detail}]`));
|
|
394
|
-
}
|
|
395
|
-
} catch (error) {
|
|
396
|
-
this.LogInfoMessage(chalk.red(`Unable to get resources from the database. Is the database running? Error: [${error}]`));
|
|
397
|
-
}
|
|
398
|
-
})();
|
|
399
|
-
}
|
|
400
|
-
return this.#accessLayer;
|
|
401
|
-
}
|
|
402
|
-
return null;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
GetNumCPUs = async (): Promise<number> => {
|
|
406
|
-
// https://systeminformation.io/
|
|
407
|
-
const valueObject = {
|
|
408
|
-
cpu: '*'
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const sysinfo = await si.get(valueObject);
|
|
412
|
-
let numCPUs = 2;
|
|
413
|
-
if (goptions.useCPUs > 0) {
|
|
414
|
-
if (goptions.useCPUs >= 1) {
|
|
415
|
-
numCPUs = goptions.useCPUs;
|
|
416
|
-
} else {
|
|
417
|
-
numCPUs = Math.round(sysinfo.cpu.cores * goptions.useCPUs);
|
|
418
|
-
}
|
|
419
|
-
} else {
|
|
420
|
-
numCPUs = sysinfo.cpu.physicalCores;
|
|
421
|
-
}
|
|
422
|
-
return numCPUs;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
LogSystemTelemetry = async () => {
|
|
426
|
-
// https://systeminformation.io/
|
|
427
|
-
const valueObject = {
|
|
428
|
-
system: '*',
|
|
429
|
-
osInfo: '*',
|
|
430
|
-
cpu: '*',
|
|
431
|
-
mem: '*'
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const sysinfo = await si.get(valueObject);
|
|
435
|
-
const numCPUs = await this.GetNumCPUs();
|
|
436
|
-
const hostname = sysinfo.osInfo.hostname;
|
|
437
|
-
|
|
438
|
-
const hostaddr = GetFirstNetworkInterface();
|
|
439
|
-
if (hostaddr !== null) {
|
|
440
|
-
this.LogInfoMessage(`Host Address: ${hostaddr}`);
|
|
441
|
-
} else {
|
|
442
|
-
this.LogInfoMessage(`Unknown Host Address.`);
|
|
443
|
-
}
|
|
444
|
-
this.LogInfoMessage(`Server starting with ${numCPUs} Cores/Threads`);
|
|
445
|
-
|
|
446
|
-
this.LogInfoMessage(`Hostname: ${hostname}`);
|
|
447
|
-
this.LogInfoMessage(`System: ${JSON.stringify(sysinfo.system)}`);
|
|
448
|
-
this.LogInfoMessage(`OS Info: ${JSON.stringify(sysinfo.osInfo)}`);
|
|
449
|
-
this.LogInfoMessage(`CPU: ${JSON.stringify(sysinfo.cpu)}`);
|
|
450
|
-
this.LogInfoMessage(`Memory: ${JSON.stringify(sysinfo.mem)}`);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
GetSignalColour = (signal: any) => {
|
|
454
|
-
let msgcolor = null;
|
|
455
|
-
if (signal === 'SIGINT') {
|
|
456
|
-
msgcolor = chalk.yellow;
|
|
457
|
-
} else {
|
|
458
|
-
msgcolor = chalk.red;
|
|
459
|
-
}
|
|
460
|
-
return msgcolor;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
emit<K extends keyof IProcessBaseEvents>(event: K, ...arg: IProcessBaseEvents[K]): this {
|
|
464
|
-
super.emit(event, arg);
|
|
465
|
-
return this;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
on<K extends keyof IProcessBaseEvents>(event: K, callback: (...arg: IProcessBaseEvents[K]) => void): this {
|
|
469
|
-
super.on(event, callback);
|
|
470
|
-
return this;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
off<K extends keyof IProcessBaseEvents>(event: K, callback: (...arg: IProcessBaseEvents[K]) => void): this {
|
|
474
|
-
super.off(event, callback);
|
|
475
|
-
return this;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/*@@
|
|
479
|
-
get redisMessageHandler(): RedisMessageHandler {
|
|
480
|
-
return this.#redisMessageHandler as RedisMessageHandler;
|
|
481
|
-
}
|
|
482
|
-
*/
|
|
483
|
-
}
|