@maioradv/nestjs-core 2.0.4 → 2.0.5
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.
|
@@ -14,7 +14,9 @@ export type ResourceGuardOptions = {
|
|
|
14
14
|
shutdownFn?: () => Promise<void>;
|
|
15
15
|
/** Optional NestJS LoggerService to use for logging. */
|
|
16
16
|
logger?: LoggerService;
|
|
17
|
-
/**
|
|
17
|
+
/** If true, logs each check with CPU/memory usage. Default: false */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
/** Optional peak logging options: log when CPU/memory exceed thresholds for a sustained period. Default sustain: 5000ms */
|
|
18
20
|
logPeaks?: {
|
|
19
21
|
cpuThreshold?: number;
|
|
20
22
|
memoryThresholdMb?: number;
|
|
@@ -14,7 +14,7 @@ class ResourceGuard {
|
|
|
14
14
|
this.opts.sustainForMs ??= 10000;
|
|
15
15
|
this.opts.hardKillAfterMs ??= 5000;
|
|
16
16
|
if (this.opts.logPeaks) {
|
|
17
|
-
this.opts.logPeaks.sustainMs ??=
|
|
17
|
+
this.opts.logPeaks.sustainMs ??= 5000;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
/** Start monitoring CPU and memory */
|
|
@@ -47,6 +47,15 @@ class ResourceGuard {
|
|
|
47
47
|
if (this.opts.memoryLimitMb && currentMemMb > this.opts.memoryLimitMb)
|
|
48
48
|
over = true;
|
|
49
49
|
}
|
|
50
|
+
if (this.opts.debug) {
|
|
51
|
+
const cpuMsg = this.opts.cpuLimit ? `CPU: ${currentCpuPercent?.toFixed(1)}%;` : '';
|
|
52
|
+
const memMsg = this.opts.memoryLimitMb ? `MEM: ${currentMemMb?.toFixed(0)}MB;` : '';
|
|
53
|
+
const msg = `${cpuMsg}${memMsg}`;
|
|
54
|
+
if (this.opts.logger)
|
|
55
|
+
this.opts.logger.debug(`${msg}`);
|
|
56
|
+
else
|
|
57
|
+
console.debug(`${msg}`);
|
|
58
|
+
}
|
|
50
59
|
this.lastTime = nowTime;
|
|
51
60
|
if (over) {
|
|
52
61
|
if (!this.overSince)
|