-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #781 from janhq/feat/add-system-resources
feat: add system resources
- Loading branch information
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface ResourceEvent { | ||
data: ResourceStatus; | ||
} | ||
|
||
export interface ResourceStatus { | ||
mem: UsedMemInfo; | ||
cpu: { | ||
usage: number; | ||
}; | ||
} | ||
|
||
export interface UsedMemInfo { | ||
total: number; | ||
used: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
cortex-js/src/infrastructure/services/resources-manager/resources-manager.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ResourcesManagerService } from './resources-manager.service'; | ||
|
||
@Module({ | ||
providers: [ResourcesManagerService], | ||
exports: [ResourcesManagerService], | ||
}) | ||
export class ResourceManagerModule {} |
28 changes: 28 additions & 0 deletions
28
cortex-js/src/infrastructure/services/resources-manager/resources-manager.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
ResourceStatus, | ||
UsedMemInfo, | ||
} from '@/domain/models/resource.interface'; | ||
import { Injectable } from '@nestjs/common'; | ||
import systemInformation, { Systeminformation } from 'systeminformation'; | ||
|
||
@Injectable() | ||
export class ResourcesManagerService { | ||
async getResourceStatuses(): Promise<ResourceStatus> { | ||
const promises = [systemInformation.currentLoad(), systemInformation.mem()]; | ||
const results = await Promise.all(promises); | ||
|
||
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.avgLoad, | ||
}, | ||
}; | ||
} | ||
} |