Add BasicMetrics to InfrastructureAgent/Index.ts

This commit is contained in:
Simon Larsen 2024-03-06 12:46:14 +00:00
parent 5a1acbce2e
commit da577b4906
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
4 changed files with 38 additions and 5 deletions

View File

@ -0,0 +1,8 @@
enum OSType {
Windows = "Windows",
Linux = "Linux",
MacOS = "MacOS",
Unknown = "Unknown"
}
export default OSType;

View File

@ -1,12 +1,16 @@
import BasicCron from 'CommonServer/Utils/BasicCron';
import { BasicMetircs } from './Utils/BasicMetrics';
import { EVERY_MINUTE } from 'Common/Utils/CronTime';
BasicCron({
jobName: 'MonitorInfrastructure',
options: {
schedule: '*/5 * * * *',
schedule: EVERY_MINUTE, // Every minute
runOnStartup: true,
},
runFunction: async () => {
console.log(await BasicMetircs.getBasicMetrics({
diskPaths: ['/'],
}));
}
})

View File

@ -13,7 +13,7 @@ export class BasicMetircs {
cpuMetrics: await this.getCPUMetrics(),
diskMetrics: await Promise.all(data.diskPaths.map(async (diskPath: string) => {
return this.getDiskUsage(diskPath)
}));
}))
}
}
@ -42,10 +42,10 @@ export class BasicMetircs {
}
public static async getCPUMetrics(): Promise<CPUMetrics> {
const cpuUsage = os.loadavg()[0];
const cpuUsage = os.loadavg()[0]; // Returns an array containing the 1, 5, and 15 minute load averages.
return {
percentUsage: cpuUsage
percentUsage: cpuUsage || 0
}
}
}

View File

@ -0,0 +1,21 @@
import OSTypeEnum from 'Common/Types/Infrastrucutre/OSType';
import os from 'node:os';
export default class OSType {
public static getOSType(): OSTypeEnum {
const platform: string = os.type()
switch (platform) {
case 'Windows_NT':
return OSTypeEnum.Windows
case 'Linux':
return OSTypeEnum.Linux
case 'Darwin':
return OSTypeEnum.MacOS
default:
return OSTypeEnum.Unknown
}
}
}