fix network resource usage calculation

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-05-16 16:50:24 +00:00
parent 34de9788ba
commit 8c71ceafcf
2 changed files with 13 additions and 10 deletions

View File

@ -44,7 +44,7 @@
},
"network": {
"type": "network",
"multiplier": 1,
"multiplier": 1000000,
"compact": true,
"unit": "MB/s"
}

7
pve.js
View File

@ -96,11 +96,14 @@ export async function getUsedResources (req, resourceMeta) {
config = config.data.data;
for (let key of Object.keys(config)) {
if (Object.keys(used).includes(key) && resourceMeta[key].type === "numeric") {
used[key] += config[key];
used[key] += Number(config[key]);
}
else if (diskprefixes.some(prefix => key.startsWith(prefix))) {
let diskInfo = await getDiskInfo(instance.node, instance.type, instance.vmid, key);
used[diskInfo.storage] += diskInfo.size;
used[diskInfo.storage] += Number(diskInfo.size);
}
else if (key.startsWith("net")) {
used.network += Number(config[key].split("rate=")[1].split(",")[0]);
}
}
}