From 1e6af24df0b084f4a5b495c91c65e5bad79232b1 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 2 Jul 2023 22:23:46 +0200 Subject: [PATCH] fix(core): update --- ts/00_commitinfo_data.ts | 2 +- ts/smartmetrics.classes.smartmetrics.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 1e6173a..528dc86 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@pushrocks/smartmetrics', - version: '2.0.2', + version: '2.0.3', description: 'easy system metrics' } diff --git a/ts/smartmetrics.classes.smartmetrics.ts b/ts/smartmetrics.classes.smartmetrics.ts index 0dbdc54..f26a6ec 100644 --- a/ts/smartmetrics.classes.smartmetrics.ts +++ b/ts/smartmetrics.classes.smartmetrics.ts @@ -34,8 +34,10 @@ export class SmartMetrics { // Ignore - this will fail if not running in a Docker container } - this.maxMemoryMB = Math.min(totalSystemMemoryMB, dockerMemoryLimitMB); - + // Set the maximum memory to the lower value between the Docker limit and the total system memory + this.maxMemoryMB = Math.min(totalSystemMemoryMB, dockerMemoryLimitMB, maxHeapSizeMB); + + // If the maximum old space size limit is greater than the maximum available memory, throw an error if (maxHeapSizeMB > this.maxMemoryMB) { throw new Error('Node.js process can use more memory than is available'); } @@ -88,7 +90,6 @@ export class SmartMetrics { memoryUsageBytes += stats[stat].memory; } - // Correct memory usage percentage calculation let memoryPercentage = Math.round((memoryUsageBytes / (this.maxMemoryMB * 1024 * 1024)) * 100 * 100) / 100; let memoryUsageText = `${memoryPercentage}% | ${this.formatBytes(memoryUsageBytes)} / ${this.formatBytes(this.maxMemoryMB * 1024 * 1024)}`;