diff --git a/packages/integrations/src/dashdot/dashdot-integration.ts b/packages/integrations/src/dashdot/dashdot-integration.ts index 11280cb743..dba301a365 100644 --- a/packages/integrations/src/dashdot/dashdot-integration.ts +++ b/packages/integrations/src/dashdot/dashdot-integration.ts @@ -4,35 +4,40 @@ import type {MemoryLoad} from "../interfaces/hardware-usage/memory-load"; import type {NetworkLoad} from "../interfaces/hardware-usage/network-load"; export class DashDotIntegration extends Integration { - public async testConnectionAsync(): Promise { - const response = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "info")); - await response.json(); - } + public async testConnectionAsync(): Promise { + const response = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "info")); + await response.json(); + } - public async getCurrentCpuLoadAsync(): Promise { - const cpu = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "load/cpu")); - const data = (await cpu.json()) as CpuLoadApi[]; - return { - sumLoad: data.reduce((acc, current) => acc + current.load, 0) / data.length, - }; - } + public async getInfoAsync(): Promise { + const infoResponse = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "info")); + return (await infoResponse.json()) as ServerInfo; + } - public async getCurrentMemoryLoadAsync(): Promise { - const memoryLoad = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "load/ram")); - const data = (await memoryLoad.json()) as MemoryLoadApi; - return { - loadInBytes: data.load - } + public async getCurrentCpuLoadAsync(): Promise { + const cpu = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "load/cpu")); + const data = (await cpu.json()) as CpuLoadApi[]; + return { + sumLoad: data.reduce((acc, current) => acc + current.load, 0) / data.length, + }; + } + + public async getCurrentMemoryLoadAsync(): Promise { + const memoryLoad = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "load/ram")); + const data = (await memoryLoad.json()) as MemoryLoadApi; + return { + loadInBytes: data.load } + } - public async getCurrentNetworkLoadAsync(): Promise { - const memoryLoad = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "load/network")); - const data = (await memoryLoad.json()) as NetworkLoadApi; - return { - down: data.down, - up: data.up - } + public async getCurrentNetworkLoadAsync(): Promise { + const memoryLoad = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "load/network")); + const data = (await memoryLoad.json()) as NetworkLoadApi; + return { + down: data.down, + up: data.up } + } } /** @@ -49,4 +54,36 @@ interface MemoryLoadApi { interface NetworkLoadApi { up: number; down: number; +} + +interface ServerInfo { + ram: { + /** + * Available memory in bytes + */ + size: number; + }, + storage: { + /** + * Size of storage in bytes + */ + size: number; + disks: { + /** + * Name of the device, e.g. sda + */ + device: string; + + /** + * Brand name of the device + */ + brand: string; + + /** + * Type of the device. + * See option "physical" of https://systeminformation.io/filesystem.html + */ + type: string; + }[] + }[] } \ No newline at end of file