From 01abbf570cf12d95d44686cd0fde25743accd3e4 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Wed, 6 Mar 2024 17:25:02 +0000 Subject: [PATCH] Update BasicMetrics and OSType files --- Common/Types/Infrastrucutre/BasicMetrics.ts | 5 ++- Common/Types/Infrastrucutre/OSType.ts | 10 +++--- Common/Types/Monitor/MonitorType.ts | 6 ++++ InfrastructureAgent/Index.ts | 12 ++++--- InfrastructureAgent/Utils/BasicMetrics.ts | 40 ++++++++++++--------- InfrastructureAgent/Utils/OSType.ts | 15 ++++---- 6 files changed, 49 insertions(+), 39 deletions(-) diff --git a/Common/Types/Infrastrucutre/BasicMetrics.ts b/Common/Types/Infrastrucutre/BasicMetrics.ts index 34fc37c45e..73ada33fde 100644 --- a/Common/Types/Infrastrucutre/BasicMetrics.ts +++ b/Common/Types/Infrastrucutre/BasicMetrics.ts @@ -16,9 +16,8 @@ export interface BasicDiskMetrics { diskPath: string; } - export default interface BasicInfrastructureMetrics { cpuMetrics: CPUMetrics; memoryMetrics: MemoryMetrics; - diskMetrics: Array -} \ No newline at end of file + diskMetrics: Array; +} diff --git a/Common/Types/Infrastrucutre/OSType.ts b/Common/Types/Infrastrucutre/OSType.ts index 996923a367..3140ed369a 100644 --- a/Common/Types/Infrastrucutre/OSType.ts +++ b/Common/Types/Infrastrucutre/OSType.ts @@ -1,8 +1,8 @@ enum OSType { - Windows = "Windows", - Linux = "Linux", - MacOS = "MacOS", - Unknown = "Unknown" + Windows = 'Windows', + Linux = 'Linux', + MacOS = 'MacOS', + Unknown = 'Unknown', } -export default OSType; \ No newline at end of file +export default OSType; diff --git a/Common/Types/Monitor/MonitorType.ts b/Common/Types/Monitor/MonitorType.ts index a8919a7002..bd93e79c44 100644 --- a/Common/Types/Monitor/MonitorType.ts +++ b/Common/Types/Monitor/MonitorType.ts @@ -71,6 +71,12 @@ export class MonitorTypeHelper { description: 'This monitor types lets you monitor any TCP or UDP port.', }, + { + monitorType: MonitorType.Server, + title: 'Server / VM', + description: + 'This monitor types lets you monitor any server, VM, or any machine.', + }, ]; return monitorTypeProps; diff --git a/InfrastructureAgent/Index.ts b/InfrastructureAgent/Index.ts index 586cda85fc..d41e672c6a 100644 --- a/InfrastructureAgent/Index.ts +++ b/InfrastructureAgent/Index.ts @@ -9,8 +9,10 @@ BasicCron({ runOnStartup: true, }, runFunction: async () => { - console.log(await BasicMetircs.getBasicMetrics({ - diskPaths: ['/'], - })); - } -}) \ No newline at end of file + console.log( + await BasicMetircs.getBasicMetrics({ + diskPaths: ['/'], + }) + ); + }, +}); diff --git a/InfrastructureAgent/Utils/BasicMetrics.ts b/InfrastructureAgent/Utils/BasicMetrics.ts index 5b096047cd..f746ff3ef1 100644 --- a/InfrastructureAgent/Utils/BasicMetrics.ts +++ b/InfrastructureAgent/Utils/BasicMetrics.ts @@ -1,32 +1,38 @@ import os from 'node:os'; import diskusage from 'diskusage'; -import BasicInfrastructureMetrics, { BasicDiskMetrics, CPUMetrics, MemoryMetrics } from 'Common/Types/Infrastrucutre/BasicMetrics'; - +import BasicInfrastructureMetrics, { + BasicDiskMetrics, + CPUMetrics, + MemoryMetrics, +} from 'Common/Types/Infrastrucutre/BasicMetrics'; export class BasicMetircs { public static async getBasicMetrics(data: { - diskPaths: string[] + diskPaths: string[]; }): Promise { - return { memoryMetrics: await this.getMemoryMetrics(), cpuMetrics: await this.getCPUMetrics(), - diskMetrics: await Promise.all(data.diskPaths.map(async (diskPath: string) => { - return this.getDiskUsage(diskPath) - })) - } + diskMetrics: await Promise.all( + data.diskPaths.map(async (diskPath: string) => { + return this.getDiskUsage(diskPath); + }) + ), + }; } - public static async getDiskUsage(diskPath: string): Promise { - let info = await diskusage.check(diskPath); + public static async getDiskUsage( + diskPath: string + ): Promise { + const info = await diskusage.check(diskPath); return { total: info.total, free: info.free, used: info.total - info.free, available: info.available, - diskPath: diskPath - } + diskPath: diskPath, + }; } public static async getMemoryMetrics(): Promise { @@ -37,15 +43,15 @@ export class BasicMetircs { return { total: totalMemory, free: freeMemory, - used: usedMemory - } + used: usedMemory, + }; } public static async getCPUMetrics(): Promise { const cpuUsage = os.loadavg()[0]; // Returns an array containing the 1, 5, and 15 minute load averages. return { - percentUsage: cpuUsage || 0 - } + percentUsage: cpuUsage || 0, + }; } -} \ No newline at end of file +} diff --git a/InfrastructureAgent/Utils/OSType.ts b/InfrastructureAgent/Utils/OSType.ts index 2731480453..c1aa6cb04d 100644 --- a/InfrastructureAgent/Utils/OSType.ts +++ b/InfrastructureAgent/Utils/OSType.ts @@ -2,20 +2,17 @@ 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() + const platform: string = os.type(); switch (platform) { case 'Windows_NT': - return OSTypeEnum.Windows + return OSTypeEnum.Windows; case 'Linux': - return OSTypeEnum.Linux + return OSTypeEnum.Linux; case 'Darwin': - return OSTypeEnum.MacOS + return OSTypeEnum.MacOS; default: - return OSTypeEnum.Unknown + return OSTypeEnum.Unknown; } } - -} \ No newline at end of file +}