Add nomad widget
This commit is contained in:
parent
063950af05
commit
35946f8cba
@ -576,5 +576,11 @@
|
||||
"people_home": "People Home",
|
||||
"lights_on": "Lights On",
|
||||
"switches_on": "Switches On"
|
||||
},
|
||||
"nomad": {
|
||||
"nodes": "Nodes",
|
||||
"jobs": "Jobs",
|
||||
"volumes": "Volumes",
|
||||
"services": "Services"
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,5 +567,11 @@
|
||||
"people_home": "People Home",
|
||||
"lights_on": "Lights On",
|
||||
"switches_on": "Switches On"
|
||||
},
|
||||
"nomad": {
|
||||
"nodes": "节点",
|
||||
"jobs": "任务",
|
||||
"volumes": "挂载",
|
||||
"services": "服务"
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,8 @@ export default async function credentialedProxyHandler(req, res, map) {
|
||||
} else {
|
||||
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
|
||||
}
|
||||
} else if (widget.type === "nomad") {
|
||||
headers["X-Nomad-Token"] = `${widget.key}`;
|
||||
} else {
|
||||
headers["X-API-Key"] = `${widget.key}`;
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ const components = {
|
||||
navidrome: dynamic(() => import("./navidrome/component")),
|
||||
nextcloud: dynamic(() => import("./nextcloud/component")),
|
||||
nextdns: dynamic(() => import("./nextdns/component")),
|
||||
nomad: dynamic(() => import("./nomad/component")),
|
||||
npm: dynamic(() => import("./npm/component")),
|
||||
nzbget: dynamic(() => import("./nzbget/component")),
|
||||
octoprint: dynamic(() => import("./octoprint/component")),
|
||||
|
||||
62
src/widgets/nomad/component.jsx
Normal file
62
src/widgets/nomad/component.jsx
Normal file
@ -0,0 +1,62 @@
|
||||
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";
|
||||
|
||||
function calcRunningService(total, current) {
|
||||
return current.Services.length + total;
|
||||
}
|
||||
|
||||
function calcReadyNode(total, current) {
|
||||
return current.Status === "ready" ? total + 1 : total;
|
||||
}
|
||||
|
||||
function calcRunningJob(total, current) {
|
||||
return current.Status === "running" ? total + 1 : total;
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
||||
const { data: nodeData, error: nodeError } = useWidgetAPI(widget, "nodes");
|
||||
const { data: jobData, error: jobError } = useWidgetAPI(widget, "jobs");
|
||||
const { data: serviceData, error: serviceError } = useWidgetAPI(widget, "services");
|
||||
const { data: volumeData, error: volumeError } = useWidgetAPI(widget, "volumes");
|
||||
const { data: csiVolumeData, error: csiVolumeError } = useWidgetAPI(widget, "csi_volumes");
|
||||
|
||||
if (nodeError || jobError || serviceError || volumeError || csiVolumeError) {
|
||||
const finalError = nodeError ?? jobError ?? serviceError ?? volumeError ?? csiVolumeError;
|
||||
return <Container error={finalError} />;
|
||||
}
|
||||
|
||||
if (!nodeData || !jobData || !serviceData || !volumeData || !csiVolumeData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="nomad.nodes" />
|
||||
<Block label="nomad.jobs" />
|
||||
<Block label="nomad.volumes" />
|
||||
<Block label="nomad.services" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const nodes = nodeData || [];
|
||||
const readyNodes = nodes.reduce(calcReadyNode, 0);
|
||||
|
||||
const jobs = jobData || [];
|
||||
const runningJobs = jobs.reduce(calcRunningJob, 0);
|
||||
|
||||
const volumeTotal = volumeData.length + csiVolumeData.length;
|
||||
const runningServices = (serviceData || []).reduce(calcRunningService, 0);
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="nomad.nodes" value={`${readyNodes} / ${nodes.length}`} />
|
||||
<Block label="nomad.jobs" value={`${runningJobs} / ${jobs.length}`} />
|
||||
<Block label="nomad.volumes" value={t("common.number", { value: volumeTotal })} />
|
||||
<Block label="nomad.services" value={t("common.number", { value: runningServices })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
26
src/widgets/nomad/widget.js
Normal file
26
src/widgets/nomad/widget.js
Normal file
@ -0,0 +1,26 @@
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/v1/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
nodes: {
|
||||
endpoint: "nodes",
|
||||
},
|
||||
jobs: {
|
||||
endpoint: "jobs",
|
||||
},
|
||||
services: {
|
||||
endpoint: "services",
|
||||
},
|
||||
volumes: {
|
||||
endpoint: "volumes",
|
||||
},
|
||||
csi_volumes: {
|
||||
endpoint: "volumes?type=csi",
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
||||
@ -37,6 +37,7 @@ import navidrome from "./navidrome/widget";
|
||||
import nextcloud from "./nextcloud/widget";
|
||||
import nextdns from "./nextdns/widget";
|
||||
import npm from "./npm/widget";
|
||||
import nomad from "./nomad/widget";
|
||||
import nzbget from "./nzbget/widget";
|
||||
import octoprint from "./octoprint/widget";
|
||||
import omada from "./omada/widget";
|
||||
@ -116,6 +117,7 @@ const widgets = {
|
||||
nextcloud,
|
||||
nextdns,
|
||||
npm,
|
||||
nomad,
|
||||
nzbget,
|
||||
octoprint,
|
||||
omada,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user