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 ce901e71d3
commit f27ea02f10
2 changed files with 13 additions and 10 deletions

View File

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

7
pve.js
View File

@ -96,11 +96,14 @@ export async function getUsedResources (req, resourceMeta) {
config = config.data.data; config = config.data.data;
for (let key of Object.keys(config)) { for (let key of Object.keys(config)) {
if (Object.keys(used).includes(key) && resourceMeta[key].type === "numeric") { 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))) { else if (diskprefixes.some(prefix => key.startsWith(prefix))) {
let diskInfo = await getDiskInfo(instance.node, instance.type, instance.vmid, key); 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]);
} }
} }
} }