Opnsense widget (#3)

* OPNSense widget : initial version, memory usage is inaccurate.

* OPNSense widget : code cleanup in widget.js. Firewall is no longer displayed, so it did not need to be queried.

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

* OPNSense widget : fixing the CPU code to make it more reliable. Removing uptime info
This commit is contained in:
Benoit SERRA 2022-12-26 07:36:36 +01:00 committed by Benoit
parent a8e506504a
commit 65143d862b

View File

@ -29,9 +29,11 @@ export default function Component({ service }) {
} }
const cpuIdle = activityData.headers[2].match(/ ([0-9.]+)% idle/)[1]; const cpuidle = activityData.headers[2].substring(60,64);
const cpu = 100 - parseFloat(cpuIdle); const cpu = 100 - parseFloat(cpuidle);
const memory = activityData.headers[3].match(/Mem: (.+) Active,/)[1]; const memoryInfos = activityData.headers[3].split(" ");
const totalMemory = parseFloat(memoryInfos[1]) + parseFloat(memoryInfos[3]) + parseFloat(memoryInfos[5]) + parseFloat(memoryInfos[7]) + parseFloat(memoryInfos[9])/1024 + parseFloat(memoryInfos[11]);
const memory = ( 1 - parseFloat(memoryInfos[11]) / totalMemory) * 100;
const wanUpload = interfaceData.interfaces.wan['bytes transmitted']; const wanUpload = interfaceData.interfaces.wan['bytes transmitted'];
const wanDownload = interfaceData.interfaces.wan['bytes received']; const wanDownload = interfaceData.interfaces.wan['bytes received'];
@ -39,7 +41,7 @@ export default function Component({ service }) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="opnsense.cpu" value={t("common.percent", { value: cpu.toFixed(2) })} /> <Block label="opnsense.cpu" value={t("common.percent", { value: cpu.toFixed(2) })} />
<Block label="opnsense.memory" value={memory} /> <Block label="opnsense.memory" value={t("common.percent", { value: memory })} />
<Block label="opnsense.wanUpload" value={t("common.bytes", { value: wanUpload })} /> <Block label="opnsense.wanUpload" value={t("common.bytes", { value: wanUpload })} />
<Block label="opnsense.wanDownload" value={t("common.bytes", { value: wanDownload })} /> <Block label="opnsense.wanDownload" value={t("common.bytes", { value: wanDownload })} />