Skip to content

Commit

Permalink
feat: add system info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw committed Aug 12, 2024
1 parent e7e01b3 commit 7bc3c58
Showing 1 changed file with 61 additions and 24 deletions.
85 changes: 61 additions & 24 deletions packages/integrations/src/dashdot/dashdot-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const response = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "info"));
await response.json();
}
public async testConnectionAsync(): Promise<void> {
const response = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "info"));
await response.json();
}

public async getCurrentCpuLoadAsync(): Promise<CpuLoad> {
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<ServerInfo> {
const infoResponse = await fetch(this.appendPathToUrlWithEndingSlash(this.integration.url, "info"));
return (await infoResponse.json()) as ServerInfo;
}

public async getCurrentMemoryLoadAsync(): Promise<MemoryLoad> {
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<CpuLoad> {
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<MemoryLoad> {
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<NetworkLoad> {
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<NetworkLoad> {
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
}
}
}

/**
Expand All @@ -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;
}[]
}[]
}

0 comments on commit 7bc3c58

Please sign in to comment.