OPNSense widget : fixing the CPU code to make it more reliable.

This commit is contained in:
Benoit 2022-12-25 21:09:42 +01:00
parent 84affae10d
commit e056298f44

View File

@ -29,8 +29,10 @@ export default function Component({ service }) {
);
}
const cpuInfos = activityData.headers[2].split(" ");
const cpu = parseFloat(cpuInfos[2]) + parseFloat(cpuInfos[5]) + parseFloat(cpuInfos[8]) + parseFloat(cpuInfos[11]);
const cpuidle = activityData.headers[2].substring(60,64);
const cpu = 100 - parseFloat(cpuidle);
const uptimeInfos = activityData.headers[0].match(/.* up ([0-9+:]*) .*/);
const uptime = uptimeInfos[1];
const memoryInfos = activityData.headers[3].split(" ");
@ -43,7 +45,7 @@ export default function Component({ service }) {
return (
<Container service={service}>
<Block label="opnsense.uptime" value={ uptime } />
<Block label="opnsense.cpu" value={t("common.percent", { value: cpu.toFixed(2) })} />
<Block label="opnsense.cpu" value={t("common.percent", { value: cpu.toFixed(4) })} />
<Block label="opnsense.memory" value={t("common.percent", { value: memory })} />
<Block label="opnsense.wanUpload" value={t("common.bytes", { value: wanUpload })} />
<Block label="opnsense.wanDownload" value={t("common.bytes", { value: wanDownload })} />