From da577b490657a7e53f264423a39dc0dbeb860aab Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Wed, 6 Mar 2024 12:46:14 +0000 Subject: [PATCH] Add BasicMetrics to InfrastructureAgent/Index.ts --- Common/Types/Infrastrucutre/OSType.ts | 8 ++++++++ InfrastructureAgent/Index.ts | 8 ++++++-- InfrastructureAgent/Utils/BasicMetrics.ts | 6 +++--- InfrastructureAgent/Utils/OSType.ts | 21 +++++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 Common/Types/Infrastrucutre/OSType.ts create mode 100644 InfrastructureAgent/Utils/OSType.ts diff --git a/Common/Types/Infrastrucutre/OSType.ts b/Common/Types/Infrastrucutre/OSType.ts new file mode 100644 index 0000000000..996923a367 --- /dev/null +++ b/Common/Types/Infrastrucutre/OSType.ts @@ -0,0 +1,8 @@ +enum OSType { + Windows = "Windows", + Linux = "Linux", + MacOS = "MacOS", + Unknown = "Unknown" +} + +export default OSType; \ No newline at end of file diff --git a/InfrastructureAgent/Index.ts b/InfrastructureAgent/Index.ts index 8dc5a68f4b..586cda85fc 100644 --- a/InfrastructureAgent/Index.ts +++ b/InfrastructureAgent/Index.ts @@ -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: ['/'], + })); } }) \ No newline at end of file diff --git a/InfrastructureAgent/Utils/BasicMetrics.ts b/InfrastructureAgent/Utils/BasicMetrics.ts index 62d8b701eb..5b096047cd 100644 --- a/InfrastructureAgent/Utils/BasicMetrics.ts +++ b/InfrastructureAgent/Utils/BasicMetrics.ts @@ -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 { - 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 } } } \ No newline at end of file diff --git a/InfrastructureAgent/Utils/OSType.ts b/InfrastructureAgent/Utils/OSType.ts new file mode 100644 index 0000000000..2731480453 --- /dev/null +++ b/InfrastructureAgent/Utils/OSType.ts @@ -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 + } + } + +} \ No newline at end of file