mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 22:48:46 +00:00
Merge main
This commit is contained in:
commit
893b3f0986
53 changed files with 1068 additions and 383 deletions
|
@ -1,16 +1,18 @@
|
|||
import Docker from "dockerode";
|
||||
|
||||
import getDockerArguments from "utils/config/docker";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("dockerStatsService");
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { service } = req.query;
|
||||
const [containerName, containerServer] = service;
|
||||
|
||||
if (!containerName && !containerServer) {
|
||||
res.status(400).send({
|
||||
return res.status(400).send({
|
||||
error: "docker query parameters are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -23,10 +25,9 @@ export default async function handler(req, res) {
|
|||
// bad docker connections can result in a <Buffer ...> object?
|
||||
// in any case, this ensures the result is the expected array
|
||||
if (!Array.isArray(containers)) {
|
||||
res.status(500).send({
|
||||
return res.status(500).send({
|
||||
error: "query failed",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const containerNames = containers.map((container) => container.Names[0].replace(/^\//, ""));
|
||||
|
@ -36,10 +37,9 @@ export default async function handler(req, res) {
|
|||
const container = docker.getContainer(containerName);
|
||||
const stats = await container.stats({ stream: false });
|
||||
|
||||
res.status(200).json({
|
||||
return res.status(200).json({
|
||||
stats,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Try with a service deployed in Docker Swarm, if enabled
|
||||
|
@ -61,19 +61,19 @@ export default async function handler(req, res) {
|
|||
const container = docker.getContainer(taskContainerId);
|
||||
const stats = await container.stats({ stream: false });
|
||||
|
||||
res.status(200).json({
|
||||
return res.status(200).json({
|
||||
stats,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).send({
|
||||
return res.status(200).send({
|
||||
error: "not found",
|
||||
});
|
||||
} catch {
|
||||
res.status(500).send({
|
||||
error: {message: "Unknown error"},
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
return res.status(500).send({
|
||||
error: {message: e?.message ?? "Unknown error"},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import Docker from "dockerode";
|
||||
|
||||
import getDockerArguments from "utils/config/docker";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("dockerStatusService");
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { service } = req.query;
|
||||
|
@ -68,9 +71,10 @@ export default async function handler(req, res) {
|
|||
return res.status(200).send({
|
||||
error: "not found",
|
||||
});
|
||||
} catch {
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
return res.status(500).send({
|
||||
error: "unknown error",
|
||||
error: {message: e?.message ?? "Unknown error"},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,17 @@ import {
|
|||
} from "utils/config/service-helpers";
|
||||
import { cleanWidgetGroups, widgetsFromConfig } from "utils/config/widget-helpers";
|
||||
|
||||
/**
|
||||
* Compares services by weight then by name.
|
||||
*/
|
||||
function compareServices(service1, service2) {
|
||||
const comp = service1.weight - service2.weight;
|
||||
if (comp !== 0) {
|
||||
return comp;
|
||||
}
|
||||
return service1.name.localeCompare(service2.name);
|
||||
}
|
||||
|
||||
export async function bookmarksResponse() {
|
||||
checkAndCopyConfig("bookmarks.yaml");
|
||||
|
||||
|
@ -112,7 +123,8 @@ export async function servicesResponse() {
|
|||
...discoveredDockerGroup.services,
|
||||
...discoveredKubernetesGroup.services,
|
||||
...configuredGroup.services
|
||||
].filter((service) => service),
|
||||
].filter((service) => service)
|
||||
.sort(compareServices),
|
||||
};
|
||||
|
||||
if (definedLayouts) {
|
||||
|
|
|
@ -33,6 +33,15 @@ export async function servicesFromConfig() {
|
|||
})),
|
||||
}));
|
||||
|
||||
// add default weight to services based on their position in the configuration
|
||||
servicesArray.forEach((group, groupIndex) => {
|
||||
group.services.forEach((service, serviceIndex) => {
|
||||
if(!service.weight) {
|
||||
servicesArray[groupIndex].services[serviceIndex].weight = (serviceIndex + 1) * 100;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return servicesArray;
|
||||
}
|
||||
|
||||
|
@ -152,6 +161,7 @@ export async function servicesFromKubernetes() {
|
|||
href: ingress.metadata.annotations[`${ANNOTATION_BASE}/href`] || getUrlFromIngress(ingress),
|
||||
name: ingress.metadata.annotations[`${ANNOTATION_BASE}/name`] || ingress.metadata.name,
|
||||
group: ingress.metadata.annotations[`${ANNOTATION_BASE}/group`] || "Kubernetes",
|
||||
weight: ingress.metadata.annotations[`${ANNOTATION_BASE}/weight`] || '0',
|
||||
icon: ingress.metadata.annotations[`${ANNOTATION_BASE}/icon`] || '',
|
||||
description: ingress.metadata.annotations[`${ANNOTATION_BASE}/description`] || '',
|
||||
};
|
||||
|
@ -201,6 +211,17 @@ export function cleanServiceGroups(groups) {
|
|||
name: serviceGroup.name,
|
||||
services: serviceGroup.services.map((service) => {
|
||||
const cleanedService = { ...service };
|
||||
if (typeof service.weight === 'string') {
|
||||
const weight = parseInt(service.weight, 10);
|
||||
if (Number.isNaN(weight)) {
|
||||
cleanedService.weight = 0;
|
||||
} else {
|
||||
cleanedService.weight = weight;
|
||||
}
|
||||
}
|
||||
if (typeof cleanedService.weight !== "number") {
|
||||
cleanedService.weight = 0;
|
||||
}
|
||||
|
||||
if (cleanedService.widget) {
|
||||
// whitelisted set of keys to pass to the frontend
|
||||
|
@ -214,12 +235,15 @@ export function cleanServiceGroups(groups) {
|
|||
defaultinterval,
|
||||
namespace, // kubernetes widget
|
||||
app,
|
||||
podSelector
|
||||
podSelector,
|
||||
wan // opnsense widget
|
||||
} = cleanedService.widget;
|
||||
|
||||
const fieldsList = typeof fields === 'string' ? JSON.parse(fields) : fields;
|
||||
|
||||
cleanedService.widget = {
|
||||
type,
|
||||
fields: fields || null,
|
||||
fields: fieldsList || null,
|
||||
service_name: service.name,
|
||||
service_group: serviceGroup.name,
|
||||
};
|
||||
|
@ -237,6 +261,9 @@ export function cleanServiceGroups(groups) {
|
|||
if (app) cleanedService.widget.app = app;
|
||||
if (podSelector) cleanedService.widget.podSelector = podSelector;
|
||||
}
|
||||
if (type === "opnsense") {
|
||||
if (wan) cleanedService.widget.wan = wan;
|
||||
}
|
||||
}
|
||||
|
||||
return cleanedService;
|
||||
|
|
|
@ -34,12 +34,18 @@ export default async function credentialedProxyHandler(req, res, map) {
|
|||
headers.Authorization = `Bearer ${widget.key}`;
|
||||
} else if (widget.type === "proxmox") {
|
||||
headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`;
|
||||
} else if (widget.type === "proxmoxbackupserver") {
|
||||
delete headers["Content-Type"];
|
||||
headers.Authorization = `PBSAPIToken=${widget.username}:${widget.password}`;
|
||||
} else if (widget.type === "autobrr") {
|
||||
headers["X-API-Token"] = `${widget.key}`;
|
||||
} else if (widget.type === "tubearchivist") {
|
||||
headers.Authorization = `Token ${widget.key}`;
|
||||
} else if (widget.type === "miniflux") {
|
||||
headers["X-Auth-Token"] = `${widget.key}`;
|
||||
} else if (widget.type === "cloudflared") {
|
||||
headers["X-Auth-Email"] = `${widget.email}`;
|
||||
headers["X-Auth-Key"] = `${widget.key}`;
|
||||
} else {
|
||||
headers["X-API-Key"] = `${widget.key}`;
|
||||
}
|
||||
|
|
31
src/widgets/cloudflared/component.jsx
Normal file
31
src/widgets/cloudflared/component.jsx
Normal file
|
@ -0,0 +1,31 @@
|
|||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "cfd_tunnel");
|
||||
|
||||
if (statsError) {
|
||||
return <Container error={statsError} />;
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="cloudflared.status" />
|
||||
<Block label="cloudflared.origin_ip" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const originIP = statsData.result.connections?.origin_ip ?? statsData.result.connections[0]?.origin_ip;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="cloudflared.status" value={statsData.result.status.charAt(0).toUpperCase() + statsData.result.status.slice(1)} />
|
||||
<Block label="cloudflared.origin_ip" value={originIP} />
|
||||
</Container>
|
||||
);
|
||||
}
|
18
src/widgets/cloudflared/widget.js
Normal file
18
src/widgets/cloudflared/widget.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "https://api.cloudflare.com/client/v4/accounts/{accountid}/{endpoint}/{tunnelid}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
"cfd_tunnel": {
|
||||
endpoint: "cfd_tunnel",
|
||||
validate: [
|
||||
"success",
|
||||
"result"
|
||||
]
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
|
@ -6,6 +6,7 @@ const components = {
|
|||
autobrr: dynamic(() => import("./autobrr/component")),
|
||||
bazarr: dynamic(() => import("./bazarr/component")),
|
||||
changedetectionio: dynamic(() => import("./changedetectionio/component")),
|
||||
cloudflared: dynamic(() => import("./cloudflared/component")),
|
||||
coinmarketcap: dynamic(() => import("./coinmarketcap/component")),
|
||||
deluge: dynamic(() => import("./deluge/component")),
|
||||
diskstation: dynamic(() => import("./diskstation/component")),
|
||||
|
@ -37,6 +38,7 @@ const components = {
|
|||
opnsense: dynamic(() => import("./opnsense/component")),
|
||||
overseerr: dynamic(() => import("./overseerr/component")),
|
||||
paperlessngx: dynamic(() => import("./paperlessngx/component")),
|
||||
proxmoxbackupserver: dynamic(() => import("./proxmoxbackupserver/component")),
|
||||
pihole: dynamic(() => import("./pihole/component")),
|
||||
plex: dynamic(() => import("./plex/component")),
|
||||
portainer: dynamic(() => import("./portainer/component")),
|
||||
|
@ -61,6 +63,7 @@ const components = {
|
|||
unifi: dynamic(() => import("./unifi/component")),
|
||||
watchtower: dynamic(() => import("./watchtower/component")),
|
||||
xteve: dynamic(() => import("./xteve/component")),
|
||||
immich: dynamic(() => import("./immich/component")),
|
||||
};
|
||||
|
||||
export default components;
|
||||
|
|
33
src/widgets/immich/component.jsx
Normal file
33
src/widgets/immich/component.jsx
Normal file
|
@ -0,0 +1,33 @@
|
|||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { widget } = service;
|
||||
|
||||
const { data: immichData, error: immichError } = useWidgetAPI(widget);
|
||||
|
||||
if (immichError || immichData?.statusCode === 401) {
|
||||
return <Container error={immichError ?? immichData} />;
|
||||
}
|
||||
|
||||
if (!immichData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="immich.users" />
|
||||
<Block label="immich.photos" />
|
||||
<Block label="immich.videos" />
|
||||
<Block label="immich.storage" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="immich.users" value={immichData.usageByUser.length} />
|
||||
<Block label="immich.photos" value={immichData.photos} />
|
||||
<Block label="immich.videos" value={immichData.videos} />
|
||||
<Block label="immich.storage" value={immichData.usage} />
|
||||
</Container>
|
||||
);
|
||||
}
|
8
src/widgets/immich/widget.js
Normal file
8
src/widgets/immich/widget.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/server-info/stats",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
};
|
||||
|
||||
export default widget;
|
|
@ -27,7 +27,7 @@ export default function Component({ service }) {
|
|||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="nzbget.rate" value={t("common.bitrate", { value: statusData.DownloadRate })} />
|
||||
<Block label="nzbget.rate" value={t("common.byterate", { value: statusData.DownloadRate })} />
|
||||
<Block
|
||||
label="nzbget.remaining"
|
||||
value={t("common.bytes", { value: statusData.RemainingSizeMB * 1024 * 1024 })}
|
||||
|
|
|
@ -33,16 +33,14 @@ export default function Component({ service }) {
|
|||
const cpu = 100 - parseFloat(cpuIdle);
|
||||
const memory = activityData.headers[3].match(/Mem: (.+) Active,/)[1];
|
||||
|
||||
const wanUpload = interfaceData.interfaces.wan['bytes transmitted'];
|
||||
const wanDownload = interfaceData.interfaces.wan['bytes received'];
|
||||
const wan = widget.wan ? interfaceData.interfaces[widget.wan] : interfaceData.interfaces.wan;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="opnsense.cpu" value={t("common.percent", { value: cpu.toFixed(2) })} />
|
||||
<Block label="opnsense.memory" value={memory} />
|
||||
<Block label="opnsense.wanUpload" value={t("common.bytes", { value: wanUpload })} />
|
||||
<Block label="opnsense.wanDownload" value={t("common.bytes", { value: wanDownload })} />
|
||||
|
||||
{wan && <Block label="opnsense.wanUpload" value={t("common.bytes", { value: wan['bytes transmitted'] })} />}
|
||||
{wan && <Block label="opnsense.wanDownload" value={t("common.bytes", { value: wan['bytes received'] })} />}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ export default function Component({ service }) {
|
|||
}
|
||||
|
||||
const { data } = clusterData ;
|
||||
const vms = data.filter(item => item.type === "qemu") || [];
|
||||
const lxc = data.filter(item => item.type === "lxc") || [];
|
||||
const vms = data.filter(item => item.type === "qemu" && item.template === 0) || [];
|
||||
const lxc = data.filter(item => item.type === "lxc" && item.template === 0) || [];
|
||||
const nodes = data.filter(item => item.type === "node") || [];
|
||||
|
||||
const runningVMs = vms.reduce(calcRunning, 0);
|
||||
|
|
45
src/widgets/proxmoxbackupserver/component.jsx
Normal file
45
src/widgets/proxmoxbackupserver/component.jsx
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: datastoreData, error: datastoreError } = useWidgetAPI(widget, "status/datastore-usage");
|
||||
const { data: tasksData, error: tasksError } = useWidgetAPI(widget, "nodes/localhost/tasks");
|
||||
const { data: hostData, error: hostError } = useWidgetAPI(widget, "nodes/localhost/status");
|
||||
|
||||
if (datastoreError || tasksError || hostError) {
|
||||
const finalError = tasksError ?? datastoreError ?? hostError;
|
||||
return <Container error={finalError} />;
|
||||
}
|
||||
|
||||
if (!datastoreData || !tasksData || !hostData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="proxmoxbackupserver.datastore_usage" />
|
||||
<Block label="proxmoxbackupserver.failed_tasks" />
|
||||
<Block label="proxmoxbackupserver.cpu_usage" />
|
||||
<Block label="proxmoxbackupserver.memory_usage" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const datastoreUsage = datastoreData.data[0].used / datastoreData.data[0].total * 100;
|
||||
const cpuUsage = hostData.data.cpu * 100;
|
||||
const memoryUsage = hostData.data.memory.used / hostData.data.memory.total * 100;
|
||||
const failedTasks = tasksData.total >= 100 ? "99+" : tasksData.total;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="proxmoxbackupserver.datastore_usage" value={t("common.percent", { value: datastoreUsage })} />
|
||||
<Block label="proxmoxbackupserver.failed_tasks_24h" value={failedTasks} />
|
||||
<Block label="proxmoxbackupserver.cpu_usage" value={t("common.percent", { value: cpuUsage })} />
|
||||
<Block label="proxmoxbackupserver.memory_usage" value={t("common.percent", { value: memoryUsage })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
22
src/widgets/proxmoxbackupserver/widget.js
Normal file
22
src/widgets/proxmoxbackupserver/widget.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const since = Date.now() - (24 * 60 * 60 * 1000);
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api2/json/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
"status/datastore-usage": {
|
||||
endpoint: "status/datastore-usage",
|
||||
},
|
||||
"nodes/localhost/tasks": {
|
||||
endpoint: `nodes/localhost/tasks?errors=true&limit=100&since=${since}`,
|
||||
},
|
||||
"nodes/localhost/status": {
|
||||
endpoint: "nodes/localhost/status",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
|
@ -3,6 +3,7 @@ import authentik from "./authentik/widget";
|
|||
import autobrr from "./autobrr/widget";
|
||||
import bazarr from "./bazarr/widget";
|
||||
import changedetectionio from "./changedetectionio/widget";
|
||||
import cloudflared from "./cloudflared/widget";
|
||||
import coinmarketcap from "./coinmarketcap/widget";
|
||||
import deluge from "./deluge/widget";
|
||||
import diskstation from "./diskstation/widget";
|
||||
|
@ -31,6 +32,7 @@ import ombi from "./ombi/widget";
|
|||
import opnsense from "./opnsense/widget";
|
||||
import overseerr from "./overseerr/widget";
|
||||
import paperlessngx from "./paperlessngx/widget";
|
||||
import proxmoxbackupserver from "./proxmoxbackupserver/widget";
|
||||
import pihole from "./pihole/widget";
|
||||
import plex from "./plex/widget";
|
||||
import portainer from "./portainer/widget";
|
||||
|
@ -55,6 +57,7 @@ import truenas from "./truenas/widget";
|
|||
import unifi from "./unifi/widget";
|
||||
import watchtower from "./watchtower/widget";
|
||||
import xteve from "./xteve/widget";
|
||||
import immich from "./immich/widget";
|
||||
|
||||
const widgets = {
|
||||
adguard,
|
||||
|
@ -62,6 +65,7 @@ const widgets = {
|
|||
autobrr,
|
||||
bazarr,
|
||||
changedetectionio,
|
||||
cloudflared,
|
||||
coinmarketcap,
|
||||
deluge,
|
||||
diskstation,
|
||||
|
@ -91,6 +95,7 @@ const widgets = {
|
|||
opnsense,
|
||||
overseerr,
|
||||
paperlessngx,
|
||||
proxmoxbackupserver,
|
||||
pihole,
|
||||
plex,
|
||||
portainer,
|
||||
|
@ -116,6 +121,7 @@ const widgets = {
|
|||
unifi_console: unifi,
|
||||
watchtower,
|
||||
xteve,
|
||||
immich,
|
||||
};
|
||||
|
||||
export default widgets;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue