Skip to content

Commit

Permalink
using system information instead
Browse files Browse the repository at this point in the history
  • Loading branch information
namchuai committed Jun 26, 2024
1 parent 045328c commit af0e3bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 0 additions & 2 deletions cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions cortex-js/src/domain/models/resource.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export interface ResourceStatus {
}

export interface UsedMemInfo {
totalMemMb: number;
usedMemMb: number;
total: number;
used: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceStatus> {
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,
},
};
}
Expand Down

0 comments on commit af0e3bd

Please sign in to comment.