Update component.jsx

Changed to accommodate multiple datastores or a specific datastore supplied in services.yaml
This commit is contained in:
choehn86 2025-01-15 22:38:44 -05:00 committed by GitHub
parent 1e556e105d
commit 2f28b7790e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 cpuUsage = hostData.data.cpu * 100;
const memoryUsage = (hostData.data.memory.used / hostData.data.memory.total) * 100; const memoryUsage = (hostData.data.memory.used / hostData.data.memory.total) * 100;
const failedTasks = tasksData.total >= 100 ? "99+" : tasksData.total; const failedTasks = tasksData.total >= 100 ? "99+" : tasksData.total;