feat(integrations): recover beszel integration from worktree
Recovered all beszel integration files from the local worktree at /Users/ajnart/.cursor/worktrees/homarr/pwxp that were built and tested with the homarr:beszel docker image.
This commit is contained in:
29 files changed
+2526
-18
No files matched your search
@@ -0,0 +1,127 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { Badge, Card, Group, Indicator, ScrollArea, Stack, Text } from "@mantine/core";
|
||||
import { IconAlertTriangle, IconBell, IconCheck } from "@tabler/icons-react";
|
||||
import dayjs from "dayjs";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
const alertColorMap: Record<string, string> = {
|
||||
triggered: "red",
|
||||
ok: "green",
|
||||
};
|
||||
|
||||
export default function BeszelAlertsWidget({
|
||||
options,
|
||||
integrationIds,
|
||||
}: WidgetComponentProps<"beszelAlerts">) {
|
||||
const t = useScopedI18n("widget.beszelAlerts");
|
||||
const [results] = clientApi.widget.beszel.getAlerts.useSuspenseQuery({
|
||||
integrationIds,
|
||||
includeHistory: options.showHistory,
|
||||
maxHistoryItems: options.maxHistoryItems,
|
||||
});
|
||||
const utils = clientApi.useUtils();
|
||||
|
||||
clientApi.widget.beszel.subscribeAlerts.useSubscription(
|
||||
{ integrationIds, includeHistory: options.showHistory, maxHistoryItems: options.maxHistoryItems },
|
||||
{
|
||||
onData(data) {
|
||||
utils.widget.beszel.getAlerts.setData(
|
||||
{ integrationIds, includeHistory: options.showHistory, maxHistoryItems: options.maxHistoryItems },
|
||||
(prev) => {
|
||||
if (!prev) return prev;
|
||||
return prev.map((r) =>
|
||||
r.integrationId === data.integrationId
|
||||
? { ...r, alerts: data.alerts.alerts, history: data.alerts.history, updatedAt: data.timestamp }
|
||||
: r,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const systemNameMap = useMemo(() => {
|
||||
const map: Record<string, string> = {};
|
||||
for (const r of results) {
|
||||
if (r.systemNameMap) {
|
||||
Object.assign(map, r.systemNameMap);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}, [results]);
|
||||
|
||||
const alerts = useMemo(
|
||||
() => results.flatMap((r) => r.alerts.map((a) => ({ ...a, _key: `${r.integrationId}:${a.id}` }))),
|
||||
[results],
|
||||
);
|
||||
|
||||
const history = useMemo(() => {
|
||||
const all = results.flatMap((r) => r.history.map((h) => ({ ...h, _key: `${r.integrationId}:${h.id}` })));
|
||||
return all.sort((a, b) => new Date(b.created).getTime() - new Date(a.created).getTime()).slice(0, options.maxHistoryItems);
|
||||
}, [results, options.maxHistoryItems]);
|
||||
|
||||
return (
|
||||
<ScrollArea h="100%">
|
||||
<Stack gap="xs" p="xs">
|
||||
{alerts.length === 0 && (
|
||||
<Group gap="xs" justify="center" py="md">
|
||||
<IconBell size={20} opacity={0.5} />
|
||||
<Text size="sm" c="dimmed">{t("empty")}</Text>
|
||||
</Group>
|
||||
)}
|
||||
|
||||
{alerts.map((alert) => {
|
||||
const state = alert.triggered ? "triggered" : "ok";
|
||||
const systemName = systemNameMap[alert.system] ?? alert.system;
|
||||
return (
|
||||
<Card key={alert._key} padding="xs" radius="sm" withBorder>
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<Indicator color={alertColorMap[state]} size={8} processing={alert.triggered}>
|
||||
{alert.triggered ? <IconAlertTriangle size={16} /> : <IconCheck size={16} />}
|
||||
</Indicator>
|
||||
<Stack gap={0}>
|
||||
<Text size="xs" fw={500}>{alert.name} > {alert.value}</Text>
|
||||
<Text size="xs" c="dimmed">{systemName}</Text>
|
||||
</Stack>
|
||||
</Group>
|
||||
<Badge size="xs" variant="light" color={alertColorMap[state]}>
|
||||
{t(`status.${state}`)}
|
||||
</Badge>
|
||||
</Group>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
|
||||
{options.showHistory && history.length > 0 && (
|
||||
<>
|
||||
<Text size="xs" fw={600} c="dimmed" mt="xs">{t("history")}</Text>
|
||||
{history.map((entry) => {
|
||||
const systemName = systemNameMap[entry.system] ?? entry.system;
|
||||
return (
|
||||
<Card key={entry._key} padding="xs" radius="sm" withBorder>
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Stack gap={0}>
|
||||
<Text size="xs" fw={500}>{entry.name}</Text>
|
||||
<Text size="xs" c="dimmed">{systemName}</Text>
|
||||
</Stack>
|
||||
<Text size="xs" c="dimmed">{dayjs(entry.created).fromNow()}</Text>
|
||||
</Group>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { IconBell } from "@tabler/icons-react";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("beszelAlerts", {
|
||||
icon: IconBell,
|
||||
supportedIntegrations: ["beszel"],
|
||||
integrationsRequired: true,
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
showHistory: factory.switch({ defaultValue: true }),
|
||||
maxHistoryItems: factory.number({ defaultValue: 10, validate: z.number().min(1).max(100) }),
|
||||
}));
|
||||
},
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
@@ -0,0 +1,205 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { Badge, Card, Group, Progress, ScrollArea, SimpleGrid, Text, Stack } from "@mantine/core";
|
||||
import {
|
||||
Activity,
|
||||
Battery,
|
||||
BatteryCharging,
|
||||
Cpu,
|
||||
HardDrive,
|
||||
MemoryStick,
|
||||
Monitor,
|
||||
Network,
|
||||
Server,
|
||||
Thermometer,
|
||||
Wifi,
|
||||
} from "lucide-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import type { BeszelSystemRow } from "../beszel/_shared/types";
|
||||
import { statusColorMap, thresholdColor, loadAvgColor } from "../beszel/_shared/colors";
|
||||
import { formatBytes, formatLoadAvg, formatPercent, formatTemp, formatUptime } from "../beszel/_shared/format";
|
||||
|
||||
const ICON_SIZE = 14;
|
||||
|
||||
interface MetricRowProps {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
value: string;
|
||||
progress?: { value: number; color: string };
|
||||
}
|
||||
|
||||
const MetricRow = ({ icon, label, value, progress }: MetricRowProps) => (
|
||||
<Group gap="xs" wrap="nowrap" py={2}>
|
||||
{icon}
|
||||
<Text size="xs" c="dimmed" miw={55}>
|
||||
{label}
|
||||
</Text>
|
||||
{progress ? (
|
||||
<Group gap={6} wrap="nowrap" style={{ flex: 1 }}>
|
||||
<Text size="xs" fw={500} miw={38} ta="right">
|
||||
{value}
|
||||
</Text>
|
||||
<Progress value={progress.value} color={progress.color} size="sm" style={{ flex: 1 }} />
|
||||
</Group>
|
||||
) : (
|
||||
<Text size="xs" fw={500}>
|
||||
{value}
|
||||
</Text>
|
||||
)}
|
||||
</Group>
|
||||
);
|
||||
|
||||
const SystemCard = ({ system, options, t }: { system: BeszelSystemRow & { _key: string }; options: WidgetComponentProps<"beszelSystemGrid">["options"]; t: ReturnType<typeof useScopedI18n<"widget.beszelSystemGrid">> }) => (
|
||||
<Card padding={6} radius="sm" withBorder>
|
||||
<Group gap="xs" mb={4}>
|
||||
<Badge
|
||||
size="xs"
|
||||
variant="dot"
|
||||
color={statusColorMap[system.status]}
|
||||
styles={{ root: { textTransform: "none" } }}
|
||||
>
|
||||
{system.name}
|
||||
</Badge>
|
||||
</Group>
|
||||
|
||||
<Stack gap={0}>
|
||||
{options.showCpu && (
|
||||
<MetricRow
|
||||
icon={<Cpu size={ICON_SIZE} />}
|
||||
label={t("metric.cpu")}
|
||||
value={formatPercent(system.cpu)}
|
||||
progress={{ value: system.cpu, color: thresholdColor(system.cpu) }}
|
||||
/>
|
||||
)}
|
||||
{options.showMemory && (
|
||||
<MetricRow
|
||||
icon={<MemoryStick size={ICON_SIZE} />}
|
||||
label={t("metric.memory")}
|
||||
value={formatPercent(system.memory)}
|
||||
progress={{ value: system.memory, color: thresholdColor(system.memory) }}
|
||||
/>
|
||||
)}
|
||||
{options.showDisk && (
|
||||
<MetricRow
|
||||
icon={<HardDrive size={ICON_SIZE} />}
|
||||
label={t("metric.disk")}
|
||||
value={formatPercent(system.disk)}
|
||||
progress={{ value: system.disk, color: thresholdColor(system.disk) }}
|
||||
/>
|
||||
)}
|
||||
{options.showGpu && system.gpu > 0 && (
|
||||
<MetricRow
|
||||
icon={<Monitor size={ICON_SIZE} />}
|
||||
label={t("metric.gpu")}
|
||||
value={formatPercent(system.gpu)}
|
||||
progress={{ value: system.gpu, color: thresholdColor(system.gpu) }}
|
||||
/>
|
||||
)}
|
||||
{options.showLoadAvg && system.loadAvg && (
|
||||
<MetricRow
|
||||
icon={<Activity size={ICON_SIZE} />}
|
||||
label={t("metric.loadAvg")}
|
||||
value={formatLoadAvg(system.loadAvg)}
|
||||
/>
|
||||
)}
|
||||
{options.showNet && (
|
||||
<MetricRow
|
||||
icon={<Network size={ICON_SIZE} />}
|
||||
label={t("metric.net")}
|
||||
value={formatBytes(system.netBytes)}
|
||||
/>
|
||||
)}
|
||||
{options.showTemp && system.temp !== null && (
|
||||
<MetricRow
|
||||
icon={<Thermometer size={ICON_SIZE} />}
|
||||
label={t("metric.temp")}
|
||||
value={formatTemp(system.temp, false)}
|
||||
/>
|
||||
)}
|
||||
{options.showBattery && system.battery && (
|
||||
<MetricRow
|
||||
icon={system.battery[1] > 0 ? <BatteryCharging size={ICON_SIZE} /> : <Battery size={ICON_SIZE} />}
|
||||
label={t("metric.battery")}
|
||||
value={`${system.battery[0]}%`}
|
||||
/>
|
||||
)}
|
||||
{options.showServices && (
|
||||
<MetricRow
|
||||
icon={<Server size={ICON_SIZE} />}
|
||||
label={t("metric.services")}
|
||||
value={String(system.services)}
|
||||
/>
|
||||
)}
|
||||
{options.showUptime && (
|
||||
<MetricRow
|
||||
icon={<Activity size={ICON_SIZE} />}
|
||||
label={t("metric.uptime")}
|
||||
value={formatUptime(system.uptime)}
|
||||
/>
|
||||
)}
|
||||
{options.showAgent && (
|
||||
<MetricRow
|
||||
icon={<Wifi size={ICON_SIZE} />}
|
||||
label={t("metric.agent")}
|
||||
value={system.agentVersion}
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
</Card>
|
||||
);
|
||||
|
||||
export default function BeszelSystemGridWidget({
|
||||
options,
|
||||
integrationIds,
|
||||
width,
|
||||
}: WidgetComponentProps<"beszelSystemGrid">) {
|
||||
const t = useScopedI18n("widget.beszelSystemGrid");
|
||||
const [results] = clientApi.widget.beszel.getSystems.useSuspenseQuery({ integrationIds });
|
||||
const utils = clientApi.useUtils();
|
||||
|
||||
clientApi.widget.beszel.subscribeSystems.useSubscription(
|
||||
{ integrationIds },
|
||||
{
|
||||
onData(data) {
|
||||
utils.widget.beszel.getSystems.setData({ integrationIds }, (prev) => {
|
||||
if (!prev) return prev;
|
||||
return prev.map((r) =>
|
||||
r.integrationId === data.integrationId ? { ...r, systems: data.systems, updatedAt: data.timestamp } : r,
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const allSystems = useMemo(
|
||||
() => results.flatMap((r) => r.systems.map((s) => ({ ...s, _key: `${r.integrationId}:${s.id}` }))),
|
||||
[results],
|
||||
);
|
||||
|
||||
const filteredSystems = useMemo(() => {
|
||||
if (options.statusFilter === "all") return allSystems;
|
||||
return allSystems.filter((s) => s.status === options.statusFilter);
|
||||
}, [allSystems, options.statusFilter]);
|
||||
|
||||
const getColCount = (w: number) => {
|
||||
if (w > 1200) return 4;
|
||||
if (w > 800) return 3;
|
||||
if (w > 500) return 2;
|
||||
return 1;
|
||||
};
|
||||
|
||||
return (
|
||||
<ScrollArea h="100%">
|
||||
<SimpleGrid cols={getColCount(width)} spacing="xs" p={0}>
|
||||
{filteredSystems.map((system) => (
|
||||
<SystemCard key={system._key} system={system} options={options} t={t} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { IconLayoutGrid } from "@tabler/icons-react";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
const statusOptions = [
|
||||
{ value: "all", label: "All Systems" },
|
||||
{ value: "up", label: "Up" },
|
||||
{ value: "down", label: "Down" },
|
||||
{ value: "paused", label: "Paused" },
|
||||
];
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("beszelSystemGrid", {
|
||||
icon: IconLayoutGrid,
|
||||
supportedIntegrations: ["beszel"],
|
||||
integrationsRequired: true,
|
||||
createOptions() {
|
||||
return optionsBuilder.from(
|
||||
(factory) => ({
|
||||
statusFilter: factory.select({ defaultValue: "all", options: statusOptions }),
|
||||
showCpu: factory.switch({ defaultValue: true }),
|
||||
showMemory: factory.switch({ defaultValue: true }),
|
||||
showDisk: factory.switch({ defaultValue: true }),
|
||||
showGpu: factory.switch({ defaultValue: true }),
|
||||
showLoadAvg: factory.switch({ defaultValue: true }),
|
||||
showNet: factory.switch({ defaultValue: true }),
|
||||
showTemp: factory.switch({ defaultValue: true }),
|
||||
showBattery: factory.switch({ defaultValue: true }),
|
||||
showServices: factory.switch({ defaultValue: true }),
|
||||
showUptime: factory.switch({ defaultValue: true }),
|
||||
showAgent: factory.switch({ defaultValue: true }),
|
||||
}),
|
||||
);
|
||||
},
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
@@ -0,0 +1,361 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { Group, ScrollArea, Select, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { AreaChart } from "@mantine/charts";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
|
||||
const formatTime = (timestamp: string) => dayjs(timestamp).format("HH:mm");
|
||||
const formatBytes = (bytes: number) => {
|
||||
if (bytes === 0) return "0 B";
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
const i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(1024));
|
||||
return `${(bytes / Math.pow(1024, i)).toFixed(1)} ${units[i]}`;
|
||||
};
|
||||
const formatBytesPerSec = (bytes: number) => `${formatBytes(bytes)}/s`;
|
||||
const formatPercent = (v: number) => `${v.toFixed(1)}%`;
|
||||
const formatGB = (v: number) => `${v.toFixed(2)} GB`;
|
||||
const formatMB = (v: number) => `${v.toFixed(1)} MB`;
|
||||
const formatMBs = (v: number) => `${v.toFixed(2)} MB/s`;
|
||||
|
||||
const compactTooltipProps = {
|
||||
wrapperStyle: { zIndex: 1000, pointerEvents: "none" as const },
|
||||
contentStyle: { padding: "4px 8px", fontSize: 11, lineHeight: 1.3 },
|
||||
labelStyle: { fontSize: 11, marginBottom: 2 },
|
||||
itemStyle: { padding: 0, fontSize: 11 },
|
||||
};
|
||||
|
||||
interface ChartPanelProps {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const ChartPanel = ({ title, subtitle, children }: ChartPanelProps) => (
|
||||
<Stack gap={4}>
|
||||
<Group gap="xs">
|
||||
<Text size="sm" fw={600}>{title}</Text>
|
||||
{subtitle && <Text size="xs" c="dimmed">{subtitle}</Text>}
|
||||
</Group>
|
||||
{children}
|
||||
</Stack>
|
||||
);
|
||||
|
||||
export default function BeszelSystemStatsWidget({
|
||||
options,
|
||||
integrationIds,
|
||||
width,
|
||||
}: WidgetComponentProps<"beszelSystemStats">) {
|
||||
const t = useScopedI18n("widget.beszelSystemStats");
|
||||
const [systemsResult] = clientApi.widget.beszel.getSystems.useSuspenseQuery({ integrationIds });
|
||||
|
||||
const systems = useMemo(
|
||||
() => systemsResult.flatMap((r) => r.systems.map((s) => ({ value: s.id, label: s.name }))),
|
||||
[systemsResult],
|
||||
);
|
||||
|
||||
const [selectedSystem, setSelectedSystem] = useState<string | null>(systems[0]?.value ?? null);
|
||||
|
||||
const [statsResult] = clientApi.widget.beszel.getSystemStats.useSuspenseQuery({
|
||||
integrationIds,
|
||||
systemId: selectedSystem ?? systems[0]?.value ?? "",
|
||||
timePeriod: options.timePeriod as "1h" | "12h" | "24h" | "1w" | "30d",
|
||||
includeDocker: options.showDockerCpu || options.showDockerMemory || options.showDockerNetwork,
|
||||
});
|
||||
|
||||
const chartHeight = 180;
|
||||
const showDocker = options.showDockerCpu || options.showDockerMemory || options.showDockerNetwork;
|
||||
|
||||
const cpuData = useMemo(() => {
|
||||
if (!statsResult?.systemStats) return [];
|
||||
return [...statsResult.systemStats].reverse().map((r) => ({
|
||||
time: formatTime(r.created),
|
||||
[t("chart.cpu.series")]: r.stats.cpu,
|
||||
}));
|
||||
}, [statsResult, t]);
|
||||
|
||||
const memoryData = useMemo(() => {
|
||||
if (!statsResult?.systemStats) return [];
|
||||
return [...statsResult.systemStats].reverse().map((r) => ({
|
||||
time: formatTime(r.created),
|
||||
[t("chart.memory.series")]: r.stats.mu / (1024 * 1024 * 1024),
|
||||
}));
|
||||
}, [statsResult, t]);
|
||||
|
||||
const diskData = useMemo(() => {
|
||||
if (!statsResult?.systemStats) return [];
|
||||
return [...statsResult.systemStats].reverse().map((r) => ({
|
||||
time: formatTime(r.created),
|
||||
[t("chart.disk.series")]: r.stats.du / (1024 * 1024 * 1024),
|
||||
}));
|
||||
}, [statsResult, t]);
|
||||
|
||||
const diskIOData = useMemo(() => {
|
||||
if (!statsResult?.systemStats) return [];
|
||||
return [...statsResult.systemStats].reverse().map((r) => ({
|
||||
time: formatTime(r.created),
|
||||
[t("chart.diskIO.read")]: r.stats.dr / (1024 * 1024),
|
||||
[t("chart.diskIO.write")]: r.stats.dw / (1024 * 1024),
|
||||
}));
|
||||
}, [statsResult, t]);
|
||||
|
||||
const networkData = useMemo(() => {
|
||||
if (!statsResult?.systemStats) return [];
|
||||
return [...statsResult.systemStats].reverse().map((r) => ({
|
||||
time: formatTime(r.created),
|
||||
[t("chart.network.sent")]: r.stats.ns,
|
||||
[t("chart.network.recv")]: r.stats.nr,
|
||||
}));
|
||||
}, [statsResult, t]);
|
||||
|
||||
const containerNames = useMemo(() => {
|
||||
if (!statsResult?.containerStats?.length) return [];
|
||||
const names = new Set<string>();
|
||||
for (const record of statsResult.containerStats) {
|
||||
for (const c of record.stats) {
|
||||
names.add(c.n);
|
||||
}
|
||||
}
|
||||
return [...names].slice(0, 15);
|
||||
}, [statsResult]);
|
||||
|
||||
const dockerCpuData = useMemo(() => {
|
||||
if (!statsResult?.containerStats?.length) return [];
|
||||
return [...statsResult.containerStats].reverse().map((record) => {
|
||||
const point: Record<string, unknown> = { time: formatTime(record.created) };
|
||||
for (const name of containerNames) {
|
||||
const container = record.stats.find((c) => c.n === name);
|
||||
point[name] = container?.c ?? 0;
|
||||
}
|
||||
return point;
|
||||
});
|
||||
}, [statsResult, containerNames]);
|
||||
|
||||
const dockerMemData = useMemo(() => {
|
||||
if (!statsResult?.containerStats?.length) return [];
|
||||
return [...statsResult.containerStats].reverse().map((record) => {
|
||||
const point: Record<string, unknown> = { time: formatTime(record.created) };
|
||||
for (const name of containerNames) {
|
||||
const container = record.stats.find((c) => c.n === name);
|
||||
point[name] = (container?.m ?? 0) / (1024 * 1024);
|
||||
}
|
||||
return point;
|
||||
});
|
||||
}, [statsResult, containerNames]);
|
||||
|
||||
const dockerNetData = useMemo(() => {
|
||||
if (!statsResult?.containerStats?.length) return [];
|
||||
return [...statsResult.containerStats].reverse().map((record) => {
|
||||
const point: Record<string, unknown> = { time: formatTime(record.created) };
|
||||
for (const name of containerNames) {
|
||||
const container = record.stats.find((c) => c.n === name);
|
||||
const netTotal = (container?.ns ?? 0) + (container?.nr ?? 0);
|
||||
point[name] = netTotal / 1024;
|
||||
}
|
||||
return point;
|
||||
});
|
||||
}, [statsResult, containerNames]);
|
||||
|
||||
const containerColors = [
|
||||
"blue.6", "teal.6", "orange.6", "grape.6", "cyan.6",
|
||||
"pink.6", "lime.6", "violet.6", "indigo.6", "yellow.6",
|
||||
"red.6", "green.6", "blue.4", "teal.4", "orange.4",
|
||||
];
|
||||
|
||||
const containerSeries = containerNames.map((name, i) => ({
|
||||
name,
|
||||
color: containerColors[i % containerColors.length]!,
|
||||
}));
|
||||
|
||||
const cols = width > 600 ? 2 : 1;
|
||||
|
||||
return (
|
||||
<ScrollArea h="100%">
|
||||
<Stack gap="md" p="sm">
|
||||
<Select
|
||||
size="xs"
|
||||
data={systems}
|
||||
value={selectedSystem}
|
||||
onChange={setSelectedSystem}
|
||||
placeholder={t("selectSystem")}
|
||||
/>
|
||||
|
||||
{statsResult && (
|
||||
<SimpleGrid cols={cols} spacing="md">
|
||||
{options.showCpu && cpuData.length > 0 && (
|
||||
<ChartPanel title={t("chart.cpu.title")} subtitle={t("chart.cpu.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={cpuData}
|
||||
dataKey="time"
|
||||
series={[{ name: t("chart.cpu.series"), color: "teal.6" }]}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.4}
|
||||
yAxisProps={{ domain: [0, 100], tickFormatter: (v: number) => `${v}%` }}
|
||||
valueFormatter={formatPercent}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
|
||||
{options.showMemory && memoryData.length > 0 && (
|
||||
<ChartPanel title={t("chart.memory.title")} subtitle={t("chart.memory.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={memoryData}
|
||||
dataKey="time"
|
||||
series={[{ name: t("chart.memory.series"), color: "teal.6" }]}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.4}
|
||||
yAxisProps={{ tickFormatter: (v: number) => `${v.toFixed(0)} GB` }}
|
||||
valueFormatter={formatGB}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
|
||||
{options.showDisk && diskData.length > 0 && (
|
||||
<ChartPanel title={t("chart.disk.title")} subtitle={t("chart.disk.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={diskData}
|
||||
dataKey="time"
|
||||
series={[{ name: t("chart.disk.series"), color: "grape.6" }]}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.4}
|
||||
yAxisProps={{ tickFormatter: (v: number) => `${v.toFixed(0)} GB` }}
|
||||
valueFormatter={formatGB}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
|
||||
{options.showDiskIO && diskIOData.length > 0 && (
|
||||
<ChartPanel title={t("chart.diskIO.title")} subtitle={t("chart.diskIO.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={diskIOData}
|
||||
dataKey="time"
|
||||
series={[
|
||||
{ name: t("chart.diskIO.read"), color: "orange.6" },
|
||||
{ name: t("chart.diskIO.write"), color: "blue.6" },
|
||||
]}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.3}
|
||||
yAxisProps={{ tickFormatter: (v: number) => `${v.toFixed(1)} MB/s` }}
|
||||
valueFormatter={formatMBs}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
withLegend
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
|
||||
{options.showNetwork && networkData.length > 0 && (
|
||||
<ChartPanel title={t("chart.network.title")} subtitle={t("chart.network.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={networkData}
|
||||
dataKey="time"
|
||||
series={[
|
||||
{ name: t("chart.network.sent"), color: "blue.6" },
|
||||
{ name: t("chart.network.recv"), color: "teal.6" },
|
||||
]}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.3}
|
||||
yAxisProps={{ tickFormatter: (v: number) => formatBytesPerSec(v) }}
|
||||
valueFormatter={(v: number) => formatBytesPerSec(v)}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
withLegend
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
|
||||
{showDocker && containerSeries.length > 0 && (
|
||||
<>
|
||||
{options.showDockerCpu && dockerCpuData.length > 0 && (
|
||||
<ChartPanel title={t("chart.dockerCpu.title")} subtitle={t("chart.dockerCpu.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={dockerCpuData}
|
||||
dataKey="time"
|
||||
type="stacked"
|
||||
series={containerSeries}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.6}
|
||||
yAxisProps={{ tickFormatter: (v: number) => `${v.toFixed(2)}%` }}
|
||||
valueFormatter={formatPercent}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
|
||||
{options.showDockerMemory && dockerMemData.length > 0 && (
|
||||
<ChartPanel title={t("chart.dockerMemory.title")} subtitle={t("chart.dockerMemory.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={dockerMemData}
|
||||
dataKey="time"
|
||||
type="stacked"
|
||||
series={containerSeries}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.6}
|
||||
yAxisProps={{ tickFormatter: (v: number) => `${v.toFixed(0)} MB` }}
|
||||
valueFormatter={formatMB}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
|
||||
{options.showDockerNetwork && dockerNetData.length > 0 && (
|
||||
<ChartPanel title={t("chart.dockerNetwork.title")} subtitle={t("chart.dockerNetwork.subtitle")}>
|
||||
<AreaChart
|
||||
h={chartHeight}
|
||||
data={dockerNetData}
|
||||
dataKey="time"
|
||||
type="stacked"
|
||||
series={containerSeries}
|
||||
curveType="monotone"
|
||||
withDots={false}
|
||||
fillOpacity={0.6}
|
||||
yAxisProps={{ tickFormatter: (v: number) => `${v.toFixed(0)} KB/s` }}
|
||||
valueFormatter={(v: number) => `${v.toFixed(1)} KB/s`}
|
||||
tooltipProps={compactTooltipProps}
|
||||
withXAxis
|
||||
withYAxis
|
||||
/>
|
||||
</ChartPanel>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</SimpleGrid>
|
||||
)}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { IconChartAreaLine } from "@tabler/icons-react";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
const timePeriodOptions = [
|
||||
{ value: "1h", label: "1 Hour" },
|
||||
{ value: "12h", label: "12 Hours" },
|
||||
{ value: "24h", label: "24 Hours" },
|
||||
{ value: "1w", label: "1 Week" },
|
||||
{ value: "30d", label: "30 Days" },
|
||||
];
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("beszelSystemStats", {
|
||||
icon: IconChartAreaLine,
|
||||
supportedIntegrations: ["beszel"],
|
||||
integrationsRequired: true,
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
timePeriod: factory.select({ defaultValue: "1h", options: timePeriodOptions }),
|
||||
showCpu: factory.switch({ defaultValue: true }),
|
||||
showMemory: factory.switch({ defaultValue: true }),
|
||||
showDisk: factory.switch({ defaultValue: true }),
|
||||
showDiskIO: factory.switch({ defaultValue: true }),
|
||||
showNetwork: factory.switch({ defaultValue: true }),
|
||||
showDockerCpu: factory.switch({ defaultValue: true }),
|
||||
showDockerMemory: factory.switch({ defaultValue: true }),
|
||||
showDockerNetwork: factory.switch({ defaultValue: true }),
|
||||
}));
|
||||
},
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
@@ -0,0 +1,280 @@
|
||||
"use client";
|
||||
|
||||
import "./styles.css";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { Group, Indicator, Progress, Text } from "@mantine/core";
|
||||
import type { DataTableColumn, DataTableSortStatus } from "mantine-datatable";
|
||||
import { DataTable } from "mantine-datatable";
|
||||
import {
|
||||
Activity,
|
||||
Battery,
|
||||
Cpu,
|
||||
HardDrive,
|
||||
MemoryStick,
|
||||
Monitor,
|
||||
Network,
|
||||
Server,
|
||||
Thermometer,
|
||||
Wifi,
|
||||
} from "lucide-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import type { BeszelSystemRow } from "../beszel/_shared/types";
|
||||
import { statusColorMap, thresholdColor, loadAvgColor } from "../beszel/_shared/colors";
|
||||
import { formatBytes, formatLoadAvg, formatPercent, formatTemp, formatUptime } from "../beszel/_shared/format";
|
||||
|
||||
const directionMultiplier: Record<string, number> = { asc: 1, desc: -1 };
|
||||
|
||||
type SystemRowWithKey = BeszelSystemRow & { _key: string };
|
||||
|
||||
interface SizeConfig {
|
||||
iconSize: number;
|
||||
fontSize: "xs" | "10px";
|
||||
progressSize: "xs" | "sm";
|
||||
cellPadding: number;
|
||||
valueMiw: number;
|
||||
}
|
||||
|
||||
const getSizeConfig = (width: number): SizeConfig => {
|
||||
if (width < 400) {
|
||||
return { iconSize: 10, fontSize: "10px", progressSize: "xs", cellPadding: 2, valueMiw: 30 };
|
||||
}
|
||||
return { iconSize: 14, fontSize: "xs", progressSize: "sm", cellPadding: 4, valueMiw: 38 };
|
||||
};
|
||||
|
||||
export default function BeszelSystemTableWidget({
|
||||
options,
|
||||
integrationIds,
|
||||
width,
|
||||
}: WidgetComponentProps<"beszelSystemTable">) {
|
||||
const t = useScopedI18n("widget.beszelSystemTable");
|
||||
const [results] = clientApi.widget.beszel.getSystems.useSuspenseQuery({ integrationIds });
|
||||
const utils = clientApi.useUtils();
|
||||
const size = getSizeConfig(width);
|
||||
|
||||
clientApi.widget.beszel.subscribeSystems.useSubscription(
|
||||
{ integrationIds },
|
||||
{
|
||||
onData(data) {
|
||||
utils.widget.beszel.getSystems.setData({ integrationIds }, (prev) => {
|
||||
if (!prev) return prev;
|
||||
return prev.map((r) =>
|
||||
r.integrationId === data.integrationId ? { ...r, systems: data.systems, updatedAt: data.timestamp } : r,
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const allSystems = useMemo(
|
||||
() => results.flatMap((r) => r.systems.map((s) => ({ ...s, _key: `${r.integrationId}:${s.id}` }))),
|
||||
[results],
|
||||
);
|
||||
|
||||
const filteredSystems = useMemo(() => {
|
||||
if (options.statusFilter === "all") return allSystems;
|
||||
return allSystems.filter((s) => s.status === options.statusFilter);
|
||||
}, [allSystems, options.statusFilter]);
|
||||
|
||||
const [sortStatus, setSortStatus] = useState<DataTableSortStatus<SystemRowWithKey>>({
|
||||
columnAccessor: options.sortBy,
|
||||
direction: options.sortDirection as "asc" | "desc",
|
||||
});
|
||||
|
||||
const sortedSystems = useMemo(() => {
|
||||
const accessor = sortStatus.columnAccessor as keyof BeszelSystemRow;
|
||||
const dir = directionMultiplier[sortStatus.direction] ?? 1;
|
||||
return [...filteredSystems].sort((a, b) => {
|
||||
const aVal = a[accessor] ?? 0;
|
||||
const bVal = b[accessor] ?? 0;
|
||||
if (typeof aVal === "string" && typeof bVal === "string") return aVal.localeCompare(bVal) * dir;
|
||||
if (typeof aVal === "number" && typeof bVal === "number") return (aVal - bVal) * dir;
|
||||
return 0;
|
||||
});
|
||||
}, [filteredSystems, sortStatus]);
|
||||
|
||||
const PercentCell = ({ value }: { value: number }) => (
|
||||
<Group gap={4} wrap="nowrap" style={{ flex: 1 }}>
|
||||
<Text size={size.fontSize} fw={500} miw={size.valueMiw} ta="right">
|
||||
{formatPercent(value)}
|
||||
</Text>
|
||||
<Progress value={value} color={thresholdColor(value)} size={size.progressSize} style={{ flex: 1 }} />
|
||||
</Group>
|
||||
);
|
||||
|
||||
const columns = useMemo((): DataTableColumn<SystemRowWithKey>[] => {
|
||||
const cols: (DataTableColumn<SystemRowWithKey> | false)[] = [
|
||||
{
|
||||
accessor: "name",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Server size={size.iconSize} />
|
||||
<Text inherit>{t("column.system")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Indicator color={statusColorMap[record.status]} size={7} />
|
||||
<Text size={size.fontSize} fw={500} truncate>
|
||||
{record.name}
|
||||
</Text>
|
||||
</Group>
|
||||
),
|
||||
},
|
||||
options.showCpu && {
|
||||
accessor: "cpu",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Cpu size={size.iconSize} />
|
||||
<Text inherit>{t("column.cpu")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <PercentCell value={record.cpu} />,
|
||||
},
|
||||
options.showMemory && {
|
||||
accessor: "memory",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<MemoryStick size={size.iconSize} />
|
||||
<Text inherit>{t("column.memory")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <PercentCell value={record.memory} />,
|
||||
},
|
||||
options.showDisk && {
|
||||
accessor: "disk",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<HardDrive size={size.iconSize} />
|
||||
<Text inherit>{t("column.disk")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <PercentCell value={record.disk} />,
|
||||
},
|
||||
options.showGpu && {
|
||||
accessor: "gpu",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Monitor size={size.iconSize} />
|
||||
<Text inherit>{t("column.gpu")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <PercentCell value={record.gpu} />,
|
||||
},
|
||||
options.showLoadAvg && {
|
||||
accessor: "loadAvg",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Activity size={size.iconSize} />
|
||||
<Text inherit>{t("column.loadAvg")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Indicator
|
||||
color={record.loadAvg ? loadAvgColor(record.loadAvg[0], record.cores) : "gray"}
|
||||
size={7}
|
||||
/>
|
||||
<Text size={size.fontSize}>{formatLoadAvg(record.loadAvg)}</Text>
|
||||
</Group>
|
||||
),
|
||||
},
|
||||
options.showNet && {
|
||||
accessor: "netBytes",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Network size={size.iconSize} />
|
||||
<Text inherit>{t("column.net")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <Text size={size.fontSize}>{formatBytes(record.netBytes)}</Text>,
|
||||
},
|
||||
options.showTemp && {
|
||||
accessor: "temp",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Thermometer size={size.iconSize} />
|
||||
<Text inherit>{t("column.temp")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <Text size={size.fontSize}>{formatTemp(record.temp, false)}</Text>,
|
||||
},
|
||||
options.showBattery && {
|
||||
accessor: "battery",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Battery size={size.iconSize} />
|
||||
<Text inherit>{t("column.battery")}</Text>
|
||||
</Group>
|
||||
),
|
||||
render: (record) => (
|
||||
<Text size={size.fontSize}>{record.battery ? `${record.battery[0]}%` : "—"}</Text>
|
||||
),
|
||||
},
|
||||
options.showServices && {
|
||||
accessor: "services",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Server size={size.iconSize} />
|
||||
<Text inherit>{t("column.services")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <Text size={size.fontSize}>{record.services}</Text>,
|
||||
},
|
||||
options.showUptime && {
|
||||
accessor: "uptime",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Activity size={size.iconSize} />
|
||||
<Text inherit>{t("column.uptime")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <Text size={size.fontSize}>{formatUptime(record.uptime)}</Text>,
|
||||
},
|
||||
options.showAgent && {
|
||||
accessor: "agentVersion",
|
||||
title: (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Wifi size={size.iconSize} />
|
||||
<Text inherit>{t("column.agent")}</Text>
|
||||
</Group>
|
||||
),
|
||||
sortable: true,
|
||||
render: (record) => <Text size={size.fontSize}>{record.agentVersion}</Text>,
|
||||
},
|
||||
];
|
||||
|
||||
return cols.filter(Boolean) as DataTableColumn<SystemRowWithKey>[];
|
||||
}, [options, t, size]);
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
withTableBorder={false}
|
||||
borderRadius={0}
|
||||
highlightOnHover
|
||||
fz={size.fontSize}
|
||||
records={sortedSystems}
|
||||
columns={columns}
|
||||
sortStatus={sortStatus}
|
||||
onSortStatusChange={setSortStatus}
|
||||
noRecordsText={t("noRecords")}
|
||||
idAccessor="_key"
|
||||
height="100%"
|
||||
className="beszel-table"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { IconTable } from "@tabler/icons-react";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
const statusOptions = [
|
||||
{ value: "all", label: "All Systems" },
|
||||
{ value: "up", label: "Up" },
|
||||
{ value: "down", label: "Down" },
|
||||
{ value: "paused", label: "Paused" },
|
||||
];
|
||||
|
||||
const sortOptions = [
|
||||
{ value: "name", label: "System" },
|
||||
{ value: "cpu", label: "CPU" },
|
||||
{ value: "memory", label: "Memory" },
|
||||
{ value: "disk", label: "Disk" },
|
||||
{ value: "gpu", label: "GPU" },
|
||||
{ value: "loadAvg", label: "Load Avg" },
|
||||
{ value: "netBytes", label: "Net" },
|
||||
{ value: "temp", label: "Temp" },
|
||||
{ value: "services", label: "Services" },
|
||||
{ value: "uptime", label: "Uptime" },
|
||||
{ value: "agentVersion", label: "Agent" },
|
||||
];
|
||||
|
||||
const sortDirectionOptions = [
|
||||
{ value: "asc", label: "Ascending" },
|
||||
{ value: "desc", label: "Descending" },
|
||||
];
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("beszelSystemTable", {
|
||||
icon: IconTable,
|
||||
supportedIntegrations: ["beszel"],
|
||||
integrationsRequired: true,
|
||||
createOptions() {
|
||||
return optionsBuilder.from(
|
||||
(factory) => ({
|
||||
statusFilter: factory.select({ defaultValue: "all", options: statusOptions }),
|
||||
sortBy: factory.select({ defaultValue: "name", options: sortOptions }),
|
||||
sortDirection: factory.select({ defaultValue: "asc", options: sortDirectionOptions }),
|
||||
showCpu: factory.switch({ defaultValue: true }),
|
||||
showMemory: factory.switch({ defaultValue: true }),
|
||||
showDisk: factory.switch({ defaultValue: true }),
|
||||
showGpu: factory.switch({ defaultValue: true }),
|
||||
showLoadAvg: factory.switch({ defaultValue: true }),
|
||||
showNet: factory.switch({ defaultValue: true }),
|
||||
showTemp: factory.switch({ defaultValue: true }),
|
||||
showBattery: factory.switch({ defaultValue: true }),
|
||||
showServices: factory.switch({ defaultValue: true }),
|
||||
showUptime: factory.switch({ defaultValue: true }),
|
||||
showAgent: factory.switch({ defaultValue: true }),
|
||||
}),
|
||||
);
|
||||
},
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
@@ -0,0 +1,18 @@
|
||||
.beszel-table th {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.beszel-table td {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.beszel-table .mantine-datatable-header-cell-sortable-icon {
|
||||
opacity: 0;
|
||||
transition: opacity 150ms;
|
||||
}
|
||||
|
||||
.beszel-table th:hover .mantine-datatable-header-cell-sortable-icon {
|
||||
opacity: 1;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { BeszelSystemStatus } from "./types";
|
||||
|
||||
export const thresholdColor = (value: number): string => {
|
||||
if (value >= 80) return "red";
|
||||
if (value >= 50) return "yellow";
|
||||
return "green";
|
||||
};
|
||||
|
||||
export const loadAvgColor = (la1: number, cores: number): string => {
|
||||
const ratio = la1 / cores;
|
||||
if (ratio >= 1.5) return "red";
|
||||
if (ratio >= 0.8) return "yellow";
|
||||
return "green";
|
||||
};
|
||||
|
||||
export const statusColorMap: Record<BeszelSystemStatus, string> = {
|
||||
up: "green",
|
||||
down: "red",
|
||||
paused: "gray",
|
||||
pending: "yellow",
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
export const formatBytes = (bytes: number): string => {
|
||||
if (bytes === 0) return "0 B/s";
|
||||
const units = ["B/s", "KB/s", "MB/s", "GB/s"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
const value = bytes / Math.pow(1024, i);
|
||||
return `${value.toFixed(value < 10 ? 2 : 1)} ${units[i]}`;
|
||||
};
|
||||
|
||||
export const formatUptime = (seconds: number): string => {
|
||||
const days = Math.floor(seconds / 86400);
|
||||
const hours = Math.floor((seconds % 86400) / 3600);
|
||||
if (days > 0) return `${days} day${days > 1 ? "s" : ""}`;
|
||||
if (hours > 0) return `${hours} hour${hours > 1 ? "s" : ""}`;
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
return `${minutes} min`;
|
||||
};
|
||||
|
||||
export const formatTemp = (celsius: number | null, fahrenheit: boolean): string => {
|
||||
if (celsius === null) return "—";
|
||||
if (fahrenheit) return `${((celsius * 9) / 5 + 32).toFixed(1)} °F`;
|
||||
return `${celsius.toFixed(2)} °C`;
|
||||
};
|
||||
|
||||
export const formatPercent = (value: number): string => `${value.toFixed(1)}%`;
|
||||
|
||||
export const formatLoadAvg = (la: [number, number, number] | null): string => {
|
||||
if (!la) return "—";
|
||||
return la.map((v) => v.toFixed(2)).join(" ");
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
export type BeszelSystemStatus = "up" | "down" | "paused" | "pending";
|
||||
|
||||
export interface BeszelSystemRow {
|
||||
id: string;
|
||||
name: string;
|
||||
status: BeszelSystemStatus;
|
||||
cpu: number;
|
||||
memory: number;
|
||||
disk: number;
|
||||
gpu: number;
|
||||
loadAvg: [number, number, number] | null;
|
||||
netBytes: number;
|
||||
temp: number | null;
|
||||
battery: [number, number] | null;
|
||||
services: number;
|
||||
uptime: number;
|
||||
agentVersion: string;
|
||||
hostname: string;
|
||||
cpuModel: string;
|
||||
cores: number;
|
||||
memoryTotal: number;
|
||||
osName: string;
|
||||
}
|
||||
@@ -48,6 +48,10 @@ import * as timetable from "./timetable";
|
||||
import * as tracearr from "./tracearr";
|
||||
import * as umami from "./umami";
|
||||
import * as ups from "./ups";
|
||||
import * as beszelSystemTable from "./beszel-system-table";
|
||||
import * as beszelSystemGrid from "./beszel-system-grid";
|
||||
import * as beszelAlerts from "./beszel-alerts";
|
||||
import * as beszelSystemStats from "./beszel-system-stats";
|
||||
import * as video from "./video";
|
||||
import * as weather from "./weather";
|
||||
|
||||
@@ -95,6 +99,10 @@ export const widgetImports = {
|
||||
speedtestTracker,
|
||||
umami,
|
||||
ups,
|
||||
beszelSystemTable,
|
||||
beszelSystemGrid,
|
||||
beszelAlerts,
|
||||
beszelSystemStats,
|
||||
} satisfies WidgetImportRecord;
|
||||
|
||||
export type WidgetImports = typeof widgetImports;
|
||||
|
||||
Reference in new issue
Block a user