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;