From 2f28b7790ef8120cf1b082b8c878f38abb6da4c7 Mon Sep 17 00:00:00 2001 From: choehn86 <42713647+choehn86@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:38:44 -0500 Subject: [PATCH] Update component.jsx Changed to accommodate multiple datastores or a specific datastore supplied in services.yaml --- src/widgets/proxmoxbackupserver/component.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/widgets/proxmoxbackupserver/component.jsx b/src/widgets/proxmoxbackupserver/component.jsx index d6320d61..45550aee 100644 --- a/src/widgets/proxmoxbackupserver/component.jsx +++ b/src/widgets/proxmoxbackupserver/component.jsx @@ -29,7 +29,15 @@ export default function Component({ service }) { ); } - const datastoreUsage = datastoreData.data ? (datastoreData.data[0].used / datastoreData.data[0].total) * 100 : 0; + // check for presence of datastore key + const hasDatastore = !!widget.datastore; + // return index of specified datastore + const datastoreIndex = hasDatastore ? datastoreData.data.findIndex(function(ds) { return ds.store == widget.datastore }) : -1; + // calculate usage for specified datastore, unless no match, then calculate for all datastores returned by API + const datastoreUsage = (datastoreIndex > -1) + ? (datastoreData.data[datastoreIndex].used / datastoreData.data[datastoreIndex].total) * 100 + : ((datastoreData.data.reduce((sum, datastore) => sum + datastore.used, 0) / (datastoreData.data.reduce((sum, datastore) => sum + datastore.total, 0)))) * 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;