mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 15:24:55 +00:00
Add BasicMetrics to InfrastructureAgent/Index.ts
This commit is contained in:
parent
5a1acbce2e
commit
da577b4906
8
Common/Types/Infrastrucutre/OSType.ts
Normal file
8
Common/Types/Infrastrucutre/OSType.ts
Normal file
@ -0,0 +1,8 @@
|
||||
enum OSType {
|
||||
Windows = "Windows",
|
||||
Linux = "Linux",
|
||||
MacOS = "MacOS",
|
||||
Unknown = "Unknown"
|
||||
}
|
||||
|
||||
export default OSType;
|
@ -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: ['/'],
|
||||
}));
|
||||
}
|
||||
})
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
21
InfrastructureAgent/Utils/OSType.ts
Normal file
21
InfrastructureAgent/Utils/OSType.ts
Normal 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user