Feature: use datasets for truenas pools
This commit is contained in:
parent
dc3382447c
commit
546d699799
@ -12,14 +12,15 @@ export default function Component({ service }) {
|
|||||||
|
|
||||||
const { data: alertData, error: alertError } = useWidgetAPI(widget, "alerts");
|
const { data: alertData, error: alertError } = useWidgetAPI(widget, "alerts");
|
||||||
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
|
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
|
||||||
const { data: poolsData, error: poolsError } = useWidgetAPI(widget, "pools");
|
const { data: poolsData, error: poolsError } = useWidgetAPI(widget, widget?.enablePools ? "pools" : null);
|
||||||
|
const { data: datasetData, error: datasetError } = useWidgetAPI(widget, widget?.enablePools ? "dataset" : null);
|
||||||
|
|
||||||
if (alertError || statusError || poolsError) {
|
if (alertError || statusError || poolsError) {
|
||||||
const finalError = alertError ?? statusError ?? poolsError;
|
const finalError = alertError ?? statusError ?? poolsError ?? datasetError;
|
||||||
return <Container service={service} error={finalError} />;
|
return <Container service={service} error={finalError} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!alertData || !statusData) {
|
if (!alertData || !statusData || (widget?.enablePools && (!poolsData || !datasetData))) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="truenas.load" />
|
<Block label="truenas.load" />
|
||||||
@ -29,7 +30,22 @@ export default function Component({ service }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const enablePools = widget?.enablePools && Array.isArray(poolsData) && poolsData.length > 0;
|
let pools = [];
|
||||||
|
const showPools =
|
||||||
|
Array.isArray(poolsData) && poolsData.length > 0 && Array.isArray(datasetData) && datasetData.length > 0;
|
||||||
|
|
||||||
|
if (showPools) {
|
||||||
|
pools = poolsData.map((pool) => {
|
||||||
|
const dataset = datasetData.find((d) => d.pool === pool.name);
|
||||||
|
return {
|
||||||
|
id: pool.id,
|
||||||
|
name: pool.name,
|
||||||
|
healthy: pool.healthy,
|
||||||
|
allocated: dataset.children.reduce((acc, d) => acc + parseInt(d.used.rawvalue, 10), 0),
|
||||||
|
free: dataset.children.reduce((acc, d) => acc + parseInt(d.available.rawvalue, 10), 0),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -38,19 +54,11 @@ export default function Component({ service }) {
|
|||||||
<Block label="truenas.uptime" value={t("common.duration", { value: statusData.uptime_seconds })} />
|
<Block label="truenas.uptime" value={t("common.duration", { value: statusData.uptime_seconds })} />
|
||||||
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
|
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
|
||||||
</Container>
|
</Container>
|
||||||
{enablePools &&
|
{showPools &&
|
||||||
poolsData
|
pools
|
||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
.map((pool) => (
|
.map((pool) => (
|
||||||
<Pool
|
<Pool key={pool.id} name={pool.name} healthy={pool.healthy} allocated={pool.allocated} free={pool.free} />
|
||||||
key={pool.id}
|
|
||||||
name={pool.name}
|
|
||||||
healthy={pool.healthy}
|
|
||||||
allocated={pool.allocated}
|
|
||||||
free={pool.free}
|
|
||||||
data={pool.data}
|
|
||||||
nasType={widget?.nasType ?? "scale"}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,19 +1,8 @@
|
|||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import prettyBytes from "pretty-bytes";
|
import prettyBytes from "pretty-bytes";
|
||||||
|
|
||||||
export default function Pool({ name, free, allocated, healthy, data, nasType }) {
|
export default function Pool({ name, free, allocated, healthy }) {
|
||||||
let total = 0;
|
const usedPercent = Math.round((allocated / (free + allocated)) * 100);
|
||||||
if (nasType === "scale") {
|
|
||||||
total = free + allocated;
|
|
||||||
} else {
|
|
||||||
allocated = 0; // eslint-disable-line no-param-reassign
|
|
||||||
for (let i = 0; i < data.length; i += 1) {
|
|
||||||
total += data[i].stats.size;
|
|
||||||
allocated += data[i].stats.allocated; // eslint-disable-line no-param-reassign
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const usedPercent = Math.round((allocated / total) * 100);
|
|
||||||
const statusColor = healthy ? "bg-green-500" : "bg-yellow-500";
|
const statusColor = healthy ? "bg-green-500" : "bg-yellow-500";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -32,7 +21,7 @@ export default function Pool({ name, free, allocated, healthy, data, nasType })
|
|||||||
</div>
|
</div>
|
||||||
<div className="self-center text-xs flex justify-end mr-1.5 pl-1 z-10 text-ellipsis overflow-hidden whitespace-nowrap">
|
<div className="self-center text-xs flex justify-end mr-1.5 pl-1 z-10 text-ellipsis overflow-hidden whitespace-nowrap">
|
||||||
<span>
|
<span>
|
||||||
{prettyBytes(allocated)} / {prettyBytes(total)}
|
{prettyBytes(allocated)} / {prettyBytes(free + allocated)}
|
||||||
</span>
|
</span>
|
||||||
<span className="pl-2">({usedPercent}%)</span>
|
<span className="pl-2">({usedPercent}%)</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -23,11 +23,11 @@ const widget = {
|
|||||||
id: entry.name,
|
id: entry.name,
|
||||||
name: entry.name,
|
name: entry.name,
|
||||||
healthy: entry.healthy,
|
healthy: entry.healthy,
|
||||||
allocated: entry.allocated,
|
|
||||||
free: entry.free,
|
|
||||||
data: entry.topology?.data ?? [],
|
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
dataset: {
|
||||||
|
endpoint: "pool/dataset",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user