From 4e69ea6088839c19a7242a4d05d97ab207927ced Mon Sep 17 00:00:00 2001
From: rgon10 <3789272+rgon10@users.noreply.github.com>
Date: Mon, 1 Apr 2024 17:32:39 -0400
Subject: [PATCH] Fix: TrueNAS Core support for pool stats (#3206)
---------
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
---
docs/widgets/services/truenas.md | 3 +++
src/utils/config/service-helpers.js | 2 ++
src/widgets/truenas/component.jsx | 10 +++++++++-
src/widgets/truenas/pool.jsx | 14 ++++++++++++--
src/widgets/truenas/widget.js | 1 +
5 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/docs/widgets/services/truenas.md b/docs/widgets/services/truenas.md
index 24350490..97bba3be 100644
--- a/docs/widgets/services/truenas.md
+++ b/docs/widgets/services/truenas.md
@@ -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
```
diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js
index bea28278..d6552253 100644
--- a/src/utils/config/service-helpers.js
+++ b/src/utils/config/service-helpers.js
@@ -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;
diff --git a/src/widgets/truenas/component.jsx b/src/widgets/truenas/component.jsx
index 872d8c64..10d45bf6 100644
--- a/src/widgets/truenas/component.jsx
+++ b/src/widgets/truenas/component.jsx
@@ -40,7 +40,15 @@ export default function Component({ service }) {
{enablePools &&
poolsData.map((pool) => (
-
+
))}
>
);
diff --git a/src/widgets/truenas/pool.jsx b/src/widgets/truenas/pool.jsx
index 8e9d0465..b92ecb68 100644
--- a/src/widgets/truenas/pool.jsx
+++ b/src/widgets/truenas/pool.jsx
@@ -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";
diff --git a/src/widgets/truenas/widget.js b/src/widgets/truenas/widget.js
index 7435b6e1..5f8a38df 100644
--- a/src/widgets/truenas/widget.js
+++ b/src/widgets/truenas/widget.js
@@ -25,6 +25,7 @@ const widget = {
healthy: entry.healthy,
allocated: entry.allocated,
free: entry.free,
+ data: entry.topology.data,
})),
},
},