Add Proxmox Backup Server Widget (#879)
* Add Proxmox Backup Server Widget * Clarification added to Failed Tasks * Refactor pbs to proxmoxbackupserver * Removing property instead of recreating object * minor code styling of proxmoxbackupserver widget --------- Co-authored-by: Eizock <> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com>pull/893/head
parent
b0f16f6612
commit
2a42d89d08
@ -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>
|
||||
);
|
||||
}
|
@ -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;
|
Loading…
Reference in new issue