From 48a65f30e097bd99559a7852a1b7330cdf32e85e Mon Sep 17 00:00:00 2001 From: marknguyen1302 Date: Wed, 10 Jul 2024 16:27:21 +0700 Subject: [PATCH] feat: add resources consumed in ps command --- .../infrastructure/commanders/ps.command.ts | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cortex-js/src/infrastructure/commanders/ps.command.ts b/cortex-js/src/infrastructure/commanders/ps.command.ts index 5d900c328..ab524bdff 100644 --- a/cortex-js/src/infrastructure/commanders/ps.command.ts +++ b/cortex-js/src/infrastructure/commanders/ps.command.ts @@ -1,4 +1,5 @@ import ora from 'ora'; +import systeminformation from 'systeminformation'; import { CommandRunner, SubCommand } from 'nest-commander'; import { PSCliUsecases } from './usecases/ps.cli.usecases'; import { SetCommandContext } from './decorators/CommandContext'; @@ -32,6 +33,30 @@ export class PSCommand extends CommandRunner { }) .then((isOnline) => { checkingSpinner.succeed(isOnline ? 'API server is online' : 'API server is offline'); - }); + }) + .then(async () => { + const table = []; + const cpuUsage = (await systeminformation.currentLoad()).currentLoad.toFixed(2); + const gpusLoad = []; + const gpus = await systeminformation.graphics(); + for (const gpu of gpus.controllers) { + const totalVram = gpu.vram || 0; + gpusLoad.push({ + totalVram, + }); + } + const memoryData = await systeminformation.mem(); + const memoryUsage = (memoryData.active / memoryData.total * 100).toFixed(2) + table.push({ + 'CPU Usage': `${cpuUsage}%`, + 'Memory Usage': `${memoryUsage}%`, + }); + if(gpusLoad.length > 0 && gpusLoad.filter(gpu => gpu.totalVram > 0).length > 0) { + table.push({ + 'VRAM': gpusLoad, + }); + } + console.table(table); + }) } } \ No newline at end of file