feat: Initial commit for health monitoring widget with graphs (Work in Progress)
This commit is contained in:
1 parent
94263c445b
commit
3b20c96c35
20 files changed
+665
-670
No files matched your search
@@ -12,6 +12,7 @@ import { QBitTorrentIntegration } from "../download-client/qbittorrent/qbittorre
|
||||
import { SabnzbdIntegration } from "../download-client/sabnzbd/sabnzbd-integration";
|
||||
import { TransmissionIntegration } from "../download-client/transmission/transmission-integration";
|
||||
import { EmbyIntegration } from "../emby/emby-integration";
|
||||
import { DashDotIntegration } from "../health-monitoring/dashdot/dashdot-integration";
|
||||
import { HomeAssistantIntegration } from "../homeassistant/homeassistant-integration";
|
||||
import { JellyfinIntegration } from "../jellyfin/jellyfin-integration";
|
||||
import { JellyseerrIntegration } from "../jellyseerr/jellyseerr-integration";
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
import { humanFileSize } from "@homarr/common";
|
||||
|
||||
import "@homarr/redis";
|
||||
|
||||
import dayjs from "dayjs";
|
||||
import { z } from "zod";
|
||||
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||
|
||||
import { createChannelEventHistory } from "../../../redis/src/lib/channel";
|
||||
import { Integration } from "../base/integration";
|
||||
import type { HealthMonitoring } from "../types";
|
||||
|
||||
export class DashDotIntegration extends Integration {
|
||||
public async testConnectionAsync(): Promise<void> {
|
||||
const response = await fetchWithTrustedCertificatesAsync(this.url("/info"));
|
||||
await response.json();
|
||||
}
|
||||
|
||||
public async getSystemInfoAsync(): Promise<HealthMonitoring> {
|
||||
const info = await this.getInfoAsync();
|
||||
const cpuLoad = await this.getCurrentCpuLoadAsync();
|
||||
const memoryLoad = await this.getCurrentMemoryLoadAsync();
|
||||
const storageLoad = await this.getCurrentStorageLoadAsync();
|
||||
|
||||
const channel = this.getChannel();
|
||||
const history = await channel.getSliceUntilTimeAsync(dayjs().subtract(15, "minutes").toDate());
|
||||
|
||||
return {
|
||||
cpuUtilization: cpuLoad.sumLoad,
|
||||
memUsed: `${memoryLoad.loadInBytes}`,
|
||||
memAvailable: `${info.maxAvailableMemoryBytes - memoryLoad.loadInBytes}`,
|
||||
fileSystem: info.storage.map((storage, index) => ({
|
||||
deviceName: `Storage ${index + 1}: (${storage.disks.map((disk) => disk.device).join(", ")})`,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
used: humanFileSize(storageLoad[index]!),
|
||||
available: `${storage.size}`,
|
||||
percentage: storageLoad[index] ? (storageLoad[index] / storage.size) * 100 : 0,
|
||||
})),
|
||||
cpuModelName: info.cpuModel === "" ? `Unknown Model (${info.cpuBrand})` : `${info.cpuModel} (${info.cpuBrand})`,
|
||||
cpuTemp: cpuLoad.averageTemperature,
|
||||
availablePkgUpdates: 0,
|
||||
rebootRequired: false,
|
||||
smart: [],
|
||||
uptime: info.uptime,
|
||||
version: `${info.operatingSystemVersion}`,
|
||||
loadAverage: {
|
||||
"1min": Math.round(this.getAverageOfCpu(history[0])),
|
||||
"5min": Math.round(this.getAverageOfCpuFlat(history.slice(0, 4))),
|
||||
"15min": Math.round(this.getAverageOfCpuFlat(history.slice(0, 14))),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async getInfoAsync() {
|
||||
const infoResponse = await fetchWithTrustedCertificatesAsync(this.url("/info"));
|
||||
const serverInfo = await internalServerInfoApi.parseAsync(await infoResponse.json());
|
||||
return {
|
||||
maxAvailableMemoryBytes: serverInfo.ram.size,
|
||||
storage: serverInfo.storage,
|
||||
cpuBrand: serverInfo.cpu.brand,
|
||||
cpuModel: serverInfo.cpu.model,
|
||||
operatingSystemVersion: `${serverInfo.os.distro} ${serverInfo.os.release} (${serverInfo.os.kernel})`,
|
||||
uptime: serverInfo.os.uptime,
|
||||
};
|
||||
}
|
||||
|
||||
private async getCurrentCpuLoadAsync() {
|
||||
const channel = this.getChannel();
|
||||
const cpu = await fetchWithTrustedCertificatesAsync(this.url("/load/cpu"));
|
||||
const data = await cpuLoadPerCoreApiList.parseAsync(await cpu.json());
|
||||
await channel.pushAsync(data);
|
||||
return {
|
||||
sumLoad: this.getAverageOfCpu(data),
|
||||
averageTemperature: data.reduce((acc, current) => acc + current.temp, 0) / data.length,
|
||||
};
|
||||
}
|
||||
|
||||
private getAverageOfCpuFlat(cpuLoad: z.infer<typeof cpuLoadPerCoreApiList>[]) {
|
||||
const averages = cpuLoad.map((load) => this.getAverageOfCpu(load));
|
||||
return averages.reduce((acc, current) => acc + current, 0) / averages.length;
|
||||
}
|
||||
|
||||
private getAverageOfCpu(cpuLoad?: z.infer<typeof cpuLoadPerCoreApiList>) {
|
||||
if (!cpuLoad) {
|
||||
return 0;
|
||||
}
|
||||
return cpuLoad.reduce((acc, current) => acc + current.load, 0) / cpuLoad.length;
|
||||
}
|
||||
|
||||
private async getCurrentStorageLoadAsync() {
|
||||
const storageLoad = await fetchWithTrustedCertificatesAsync(this.url("/load/storage"));
|
||||
return (await storageLoad.json()) as number[];
|
||||
}
|
||||
|
||||
private async getCurrentMemoryLoadAsync() {
|
||||
const memoryLoad = await fetchWithTrustedCertificatesAsync(this.url("/load/ram"));
|
||||
const data = await memoryLoadApi.parseAsync(await memoryLoad.json());
|
||||
return {
|
||||
loadInBytes: data.load,
|
||||
};
|
||||
}
|
||||
|
||||
private getChannel() {
|
||||
return createChannelEventHistory<z.infer<typeof cpuLoadPerCoreApiList>>(
|
||||
`integration:${this.integration.id}:history:cpu`,
|
||||
100,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const cpuLoadPerCoreApi = z.object({
|
||||
load: z.number().min(0),
|
||||
temp: z.number().min(0),
|
||||
});
|
||||
|
||||
const memoryLoadApi = z.object({
|
||||
load: z.number().min(0),
|
||||
});
|
||||
|
||||
const internalServerInfoApi = z.object({
|
||||
os: z.object({
|
||||
distro: z.string(),
|
||||
kernel: z.string(),
|
||||
release: z.string(),
|
||||
uptime: z.number().min(0),
|
||||
}),
|
||||
cpu: z.object({
|
||||
brand: z.string(),
|
||||
model: z.string(),
|
||||
}),
|
||||
ram: z.object({
|
||||
size: z.number().min(0),
|
||||
}),
|
||||
storage: z.array(
|
||||
z.object({
|
||||
size: z.number().min(0),
|
||||
disks: z.array(
|
||||
z.object({
|
||||
device: z.string(),
|
||||
brand: z.string(),
|
||||
type: z.string(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
const cpuLoadPerCoreApiList = z.array(cpuLoadPerCoreApi);
|
||||
@@ -0,0 +1,80 @@
|
||||
import type { z, ZodType } from "zod";
|
||||
|
||||
import type { HealthMonitoring } from "../../interfaces/health-monitoring/healt-monitoring-data";
|
||||
import { HealthMonitoringIntegration } from "../../interfaces/health-monitoring/health-monitoring-interface";
|
||||
import {
|
||||
configSchema,
|
||||
cpuLoadSchema,
|
||||
memoryLoadSchema,
|
||||
networkLoadSchema,
|
||||
serverInfoSchema,
|
||||
storageLoadSchema,
|
||||
} from "./dashdot-schema";
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||
|
||||
export class DashDotIntegration extends HealthMonitoringIntegration {
|
||||
public async testConnectionAsync(): Promise<void> {
|
||||
const response = await fetchWithTrustedCertificatesAsync(this.url("/info"));
|
||||
await response.json();
|
||||
}
|
||||
|
||||
public async getSystemInfoAsync(): Promise<HealthMonitoring> {
|
||||
const { config } = await this.dashDotApiCallAsync("/config", configSchema);
|
||||
const info = await this.dashDotApiCallAsync("/info", serverInfoSchema);
|
||||
const cpuLoad = await this.dashDotApiCallAsync("/load/cpu", cpuLoadSchema);
|
||||
const memoryLoad = await this.dashDotApiCallAsync("/load/ram", memoryLoadSchema);
|
||||
const storageLoad = await this.dashDotApiCallAsync("/load/storage", storageLoadSchema);
|
||||
const networkLoad = await this.dashDotApiCallAsync("/load/network", networkLoadSchema);
|
||||
return {
|
||||
system: {
|
||||
name: config.override.os ?? info.os.distro,
|
||||
type: "single",
|
||||
version: info.os.release,
|
||||
uptime: info.os.uptime * 1000,
|
||||
},
|
||||
cpu: cpuLoad.map((cpu) => {
|
||||
return {
|
||||
id: `${cpu.core}`,
|
||||
name: `${cpu.core}`,
|
||||
temp: cpu.temp ? (config.use_imperial ? (cpu.temp - 32) / 1.8 : cpu.temp) : undefined,
|
||||
maxValue: 100,
|
||||
};
|
||||
}),
|
||||
memory: [
|
||||
{
|
||||
id: "unique",
|
||||
name: `${config.override.ram_brand ?? info.ram.layout[0].brand} - ${config.override.ram_type ?? info.ram.layout[0].type}`,
|
||||
maxValue: config.override.ram_size ?? info.ram.size,
|
||||
},
|
||||
],
|
||||
storage: info.storage.map((storage, index) => {
|
||||
return {
|
||||
name: storage.disks.map((disk) => config.override.storage_brands?.[disk.brand] ?? disk.brand).join(", "),
|
||||
used: storageLoad[index] ?? -1,
|
||||
size: storage.size,
|
||||
};
|
||||
}),
|
||||
network: [
|
||||
{
|
||||
id: "unique",
|
||||
name: config.use_network_interface,
|
||||
maxValue: ((config.override.network_interface_speed ?? info.network.interfaceSpeed) * 1000 ** 3) / 8,
|
||||
},
|
||||
],
|
||||
history: [
|
||||
{
|
||||
timestamp: Date.now(),
|
||||
cpu: cpuLoad.map(({ core, load }) => ({ id: `${core}`, value: load })),
|
||||
memory: [{ id: "unique", value: memoryLoad.load }],
|
||||
networkUp: [{ id: "unique", value: Math.round(networkLoad.up) }],
|
||||
networkDown: [{ id: "unique", value: Math.round(networkLoad.down) }],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
private async dashDotApiCallAsync<T extends ZodType>(path: `/${string}`, schema: T): Promise<z.infer<T>> {
|
||||
const response = await fetchWithTrustedCertificatesAsync(this.url(path));
|
||||
return await schema.parseAsync(await response.json()) as Promise<z.infer<T>>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const cpuLoadSchema = z.array(
|
||||
z.object({
|
||||
load: z.number().min(0),
|
||||
temp: z.number().min(0).optional(),
|
||||
core: z.number(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const memoryLoadSchema = z.object({
|
||||
load: z.number().min(0),
|
||||
});
|
||||
|
||||
export const storageLoadSchema = z.array(z.number().min(0));
|
||||
|
||||
export const networkLoadSchema = z.object({
|
||||
up: z.number().min(0),
|
||||
down: z.number().min(0),
|
||||
});
|
||||
|
||||
export const serverInfoSchema = z.object({
|
||||
os: z.object({
|
||||
distro: z.string(),
|
||||
kernel: z.string(),
|
||||
release: z.string(),
|
||||
uptime: z.number().min(0),
|
||||
}),
|
||||
cpu: z.object({
|
||||
brand: z.string(),
|
||||
model: z.string(),
|
||||
}),
|
||||
ram: z.object({
|
||||
size: z.number().min(0),
|
||||
layout: z.array(z.object({ brand: z.string(), type: z.string() })).nonempty(),
|
||||
}),
|
||||
storage: z.array(
|
||||
z.object({
|
||||
size: z.number().min(0),
|
||||
disks: z.array(
|
||||
z.object({
|
||||
device: z.string(),
|
||||
brand: z.string(),
|
||||
type: z.string(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
network: z.object({
|
||||
interfaceSpeed: z
|
||||
.number()
|
||||
.min(0)
|
||||
.transform((speed) => speed / 1000),
|
||||
type: z.enum(["Wireless", "Bridge", "Bond", "TAP", "Wired"]),
|
||||
}),
|
||||
});
|
||||
|
||||
export const configSchema = z.object({
|
||||
config: z.object({
|
||||
use_network_interface: z.string().default("UNKNOWN"),
|
||||
network_speed_as_bytes: z.boolean(),
|
||||
fs_virtual_mounts: z.array(z.string()),
|
||||
use_imperial: z.boolean(),
|
||||
override: z
|
||||
.object({
|
||||
os: z.string(),
|
||||
cpu_brand: z.string(),
|
||||
cpu_model: z.string(),
|
||||
cpu_frequency: z.number().min(0),
|
||||
ram_brand: z.string(),
|
||||
ram_size: z.number().min(0),
|
||||
ram_type: z.string(),
|
||||
ram_frequency: z.number().min(0),
|
||||
storage_brands: z.record(z.string(), z.string()),
|
||||
storage_sizes: z.record(z.string(), z.number().min(0)),
|
||||
storage_types: z.record(z.string(), z.string()),
|
||||
network_interface_speed: z
|
||||
.number()
|
||||
.min(0)
|
||||
.transform((speed) => speed / 1000),
|
||||
})
|
||||
.partial(),
|
||||
}),
|
||||
});
|
||||
Whitespace-only changes.
@@ -21,13 +21,15 @@ export { ProwlarrIntegration } from "./prowlarr/prowlarr-integration";
|
||||
export { LidarrIntegration } from "./media-organizer/lidarr/lidarr-integration";
|
||||
export { ReadarrIntegration } from "./media-organizer/readarr/readarr-integration";
|
||||
export { NextcloudIntegration } from "./nextcloud/nextcloud.integration";
|
||||
export { DashDotIntegration } from "./health-monitoring/dashdot/dashdot-integration";
|
||||
export { HealthMonitoringIntegration } from "./interfaces/health-monitoring/health-monitoring-interface";
|
||||
|
||||
// Types
|
||||
export type { IntegrationInput } from "./base/integration";
|
||||
export type { DownloadClientJobsAndStatus } from "./interfaces/downloads/download-client-data";
|
||||
export type { ExtendedDownloadClientItem } from "./interfaces/downloads/download-client-items";
|
||||
export type { ExtendedClientStatus } from "./interfaces/downloads/download-client-status";
|
||||
export type { HealthMonitoring } from "./interfaces/health-monitoring/healt-monitoring";
|
||||
export type { HealthMonitoring } from "./interfaces/health-monitoring/healt-monitoring-data";
|
||||
export { MediaRequestStatus } from "./interfaces/media-requests/media-request";
|
||||
export type { MediaRequestList, MediaRequestStats } from "./interfaces/media-requests/media-request";
|
||||
export type { StreamSession } from "./interfaces/media-server/session";
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { AtLeastOneOf } from "@homarr/common/types";
|
||||
|
||||
// Array in this interface are for multiple of the component, while following internal arrays are for historical data
|
||||
export interface HealthMonitoring {
|
||||
system: SystemInfos; //General system information
|
||||
cpu: (CpuExtraStats & StatsBase)[]; //Per core or Per node model
|
||||
memory: StatsBase[]; //Per system/node model
|
||||
network: StatsBase[]; //Per network interface, to be revisited if needed
|
||||
storage: StorageStats[]; //Per disk, not influenced by cluster
|
||||
history: AtLeastOneOf<HistoricalData>;
|
||||
}
|
||||
|
||||
interface StatsBase {
|
||||
id: string;
|
||||
name: string;
|
||||
maxValue: number;
|
||||
}
|
||||
|
||||
interface HistoricalData {
|
||||
timestamp: number;
|
||||
cpu: HistoryElement[];
|
||||
memory: HistoryElement[];
|
||||
networkUp: HistoryElement[];
|
||||
networkDown: HistoryElement[];
|
||||
}
|
||||
|
||||
interface HistoryElement {
|
||||
id: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
interface SystemInfos {
|
||||
name: string;
|
||||
type: "single" | "cluster";
|
||||
version: string;
|
||||
uptime: number;
|
||||
rebootRequired?: boolean;
|
||||
updateAvailable?: boolean;
|
||||
}
|
||||
|
||||
interface CpuExtraStats {
|
||||
status?: unknown;
|
||||
temp?: number;
|
||||
}
|
||||
|
||||
interface StorageStats {
|
||||
name: string;
|
||||
used: number;
|
||||
size: number;
|
||||
temp?: number;
|
||||
smartStatus?: string;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
export interface HealthMonitoring {
|
||||
version: string;
|
||||
cpuModelName: string;
|
||||
cpuUtilization: number;
|
||||
memUsed: string;
|
||||
memAvailable: string;
|
||||
uptime: number;
|
||||
loadAverage: {
|
||||
"1min": number;
|
||||
"5min": number;
|
||||
"15min": number;
|
||||
};
|
||||
rebootRequired: boolean;
|
||||
availablePkgUpdates: number;
|
||||
cpuTemp: number | undefined;
|
||||
fileSystem: {
|
||||
deviceName: string;
|
||||
used: string;
|
||||
available: string;
|
||||
percentage: number;
|
||||
}[];
|
||||
smart: {
|
||||
deviceName: string;
|
||||
temperature: number | null;
|
||||
overallStatus: string;
|
||||
}[];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Integration } from "../../base/integration";
|
||||
import type { HealthMonitoring } from "./healt-monitoring-data";
|
||||
|
||||
export abstract class HealthMonitoringIntegration extends Integration {
|
||||
public abstract getSystemInfoAsync(): Promise<HealthMonitoring>;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
export * from "./calendar-types";
|
||||
export * from "./interfaces/dns-hole-summary/dns-hole-summary-types";
|
||||
export * from "./interfaces/network-controller-summary/network-controller-summary-types";
|
||||
export * from "./interfaces/health-monitoring/healt-monitoring";
|
||||
export * from "./interfaces/health-monitoring/healt-monitoring-data";
|
||||
export * from "./interfaces/indexer-manager/indexer";
|
||||
export * from "./interfaces/media-requests/media-request";
|
||||
export * from "./base/searchable-integration";
|
||||
|
||||
Reference in new issue
Block a user