mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Update BasicMetrics and OSType files
This commit is contained in:
@@ -16,9 +16,8 @@ export interface BasicDiskMetrics {
|
||||
diskPath: string;
|
||||
}
|
||||
|
||||
|
||||
export default interface BasicInfrastructureMetrics {
|
||||
cpuMetrics: CPUMetrics;
|
||||
memoryMetrics: MemoryMetrics;
|
||||
diskMetrics: Array<BasicDiskMetrics>
|
||||
}
|
||||
diskMetrics: Array<BasicDiskMetrics>;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
export default OSType;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -9,8 +9,10 @@ BasicCron({
|
||||
runOnStartup: true,
|
||||
},
|
||||
runFunction: async () => {
|
||||
console.log(await BasicMetircs.getBasicMetrics({
|
||||
diskPaths: ['/'],
|
||||
}));
|
||||
}
|
||||
})
|
||||
console.log(
|
||||
await BasicMetircs.getBasicMetrics({
|
||||
diskPaths: ['/'],
|
||||
})
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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<BasicInfrastructureMetrics> {
|
||||
|
||||
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<BasicDiskMetrics> {
|
||||
let info = await diskusage.check(diskPath);
|
||||
public static async getDiskUsage(
|
||||
diskPath: string
|
||||
): Promise<BasicDiskMetrics> {
|
||||
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<MemoryMetrics> {
|
||||
@@ -37,15 +43,15 @@ export class BasicMetircs {
|
||||
return {
|
||||
total: totalMemory,
|
||||
free: freeMemory,
|
||||
used: usedMemory
|
||||
}
|
||||
used: usedMemory,
|
||||
};
|
||||
}
|
||||
|
||||
public static async getCPUMetrics(): Promise<CPUMetrics> {
|
||||
const cpuUsage = os.loadavg()[0]; // Returns an array containing the 1, 5, and 15 minute load averages.
|
||||
|
||||
return {
|
||||
percentUsage: cpuUsage || 0
|
||||
}
|
||||
percentUsage: cpuUsage || 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user