Fix: TrueNAS Core support for pool stats (#3206)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/3221/head
rgon10 8 months ago committed by GitHub
parent 268d8efa0e
commit 4e69ea6088
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -11,6 +11,8 @@ To create an API Key, follow [the official TrueNAS documentation](https://www.tr
A detailed pool listing is disabled by default, but can be enabled with the `enablePools` option.
To use the `enablePools` option with TrueNAS Core, the `nasType` parameter is required.
```yaml
widget:
type: truenas
@ -19,4 +21,5 @@ widget:
password: pass # not required if using api key
key: yourtruenasapikey # not required if using username / password
enablePools: true # optional, defaults to false
nasType: scale # defaults to scale, must be set to 'core' if using enablePools with TrueNAS Core
```

@ -450,6 +450,7 @@ export function cleanServiceGroups(groups) {
// truenas
enablePools,
nasType,
// unifi
site,
@ -522,6 +523,7 @@ export function cleanServiceGroups(groups) {
}
if (type === "truenas") {
if (enablePools !== undefined) cleanedService.widget.enablePools = JSON.parse(enablePools);
if (nasType !== undefined) cleanedService.widget.nasType = nasType;
}
if (["diskstation", "qnap"].includes(type)) {
if (volume) cleanedService.widget.volume = volume;

@ -40,7 +40,15 @@ export default function Component({ service }) {
</Container>
{enablePools &&
poolsData.map((pool) => (
<Pool key={pool.id} name={pool.name} healthy={pool.healthy} allocated={pool.allocated} free={pool.free} />
<Pool
key={pool.id}
name={pool.name}
healthy={pool.healthy}
allocated={pool.allocated}
free={pool.free}
data={pool.data}
nasType={widget?.nasType ?? "scale"}
/>
))}
</>
);

@ -1,8 +1,18 @@
import classNames from "classnames";
import prettyBytes from "pretty-bytes";
export default function Pool({ name, free, allocated, healthy }) {
const total = free + allocated;
export default function Pool({ name, free, allocated, healthy, data, nasType }) {
let total = 0;
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";

@ -25,6 +25,7 @@ const widget = {
healthy: entry.healthy,
allocated: entry.allocated,
free: entry.free,
data: entry.topology.data,
})),
},
},

Loading…
Cancel
Save