From af0e3bd69b43b76f9193922195252d37bfd908f5 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 26 Jun 2024 22:53:56 +0700 Subject: [PATCH] using system information instead --- cortex-js/package.json | 2 -- cortex-js/src/domain/models/resource.interface.ts | 4 ++-- .../resources-manager/resources-manager.service.ts | 14 +++++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cortex-js/package.json b/cortex-js/package.json index 4a4db8592..8f433f591 100644 --- a/cortex-js/package.json +++ b/cortex-js/package.json @@ -53,7 +53,6 @@ "decompress": "^4.2.1", "js-yaml": "^4.1.0", "nest-commander": "^3.13.0", - "node-os-utils": "^1.3.7", "openai": "^4.50.0", "readline": "^1.3.0", "reflect-metadata": "^0.2.0", @@ -76,7 +75,6 @@ "@types/jest": "^29.5.2", "@types/js-yaml": "^4.0.9", "@types/node": "^20.12.9", - "@types/node-os-utils": "^1.3.4", "@types/supertest": "^6.0.2", "@types/update-notifier": "^6.0.8", "@types/uuid": "^9.0.8", diff --git a/cortex-js/src/domain/models/resource.interface.ts b/cortex-js/src/domain/models/resource.interface.ts index 17be7d275..72741d7f7 100644 --- a/cortex-js/src/domain/models/resource.interface.ts +++ b/cortex-js/src/domain/models/resource.interface.ts @@ -10,6 +10,6 @@ export interface ResourceStatus { } export interface UsedMemInfo { - totalMemMb: number; - usedMemMb: number; + total: number; + used: number; } diff --git a/cortex-js/src/infrastructure/services/resources-manager/resources-manager.service.ts b/cortex-js/src/infrastructure/services/resources-manager/resources-manager.service.ts index 96e173ff3..266015742 100644 --- a/cortex-js/src/infrastructure/services/resources-manager/resources-manager.service.ts +++ b/cortex-js/src/infrastructure/services/resources-manager/resources-manager.service.ts @@ -3,21 +3,25 @@ import { UsedMemInfo, } from '@/domain/models/resource.interface'; import { Injectable } from '@nestjs/common'; -import { cpu, mem } from 'node-os-utils'; +import systemInformation, { Systeminformation } from 'systeminformation'; @Injectable() export class ResourcesManagerService { async getResourceStatuses(): Promise { - const promises = [cpu.usage(), mem.used()]; + const promises = [systemInformation.currentLoad(), systemInformation.mem()]; const results = await Promise.all(promises); - const cpuUsage = results[0] as number; - const memInfo = results[1] as UsedMemInfo; + const cpuUsage = results[0] as Systeminformation.CurrentLoadData; + const memory = results[1] as Systeminformation.MemData; + const memInfo: UsedMemInfo = { + total: memory.total, + used: memory.used, + }; return { mem: memInfo, cpu: { - usage: cpuUsage, + usage: cpuUsage.avgLoad, }, }; }