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:
parent
b4d64e5e80
commit
8926e2f194
@ -20,7 +20,6 @@ export default function Component({ service }) {
|
|||||||
if (!activityData || !interfaceData) {
|
if (!activityData || !interfaceData) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="opnsense.uptime" />
|
|
||||||
<Block label="opnsense.cpu" />
|
<Block label="opnsense.cpu" />
|
||||||
<Block label="opnsense.memory" />
|
<Block label="opnsense.memory" />
|
||||||
<Block label="opnsense.wanUpload" />
|
<Block label="opnsense.wanUpload" />
|
||||||
@ -29,10 +28,9 @@ 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 uptimeInfos = activityData.headers[0].match(/.* up ([0-9+:]*) .*/);
|
const cpu = 100 - parseFloat(cpuidle);
|
||||||
const uptime = uptimeInfos[1];
|
|
||||||
const memoryInfos = activityData.headers[3].split(" ");
|
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 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 memory = ( 1 - parseFloat(memoryInfos[11]) / totalMemory) * 100;
|
||||||
@ -42,7 +40,6 @@ export default function Component({ service }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<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(2) })} />
|
||||||
<Block label="opnsense.memory" value={t("common.percent", { 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 })} />
|
||||||
|
|||||||
@ -8,9 +8,15 @@ const widget = {
|
|||||||
mappings: {
|
mappings: {
|
||||||
activity: {
|
activity: {
|
||||||
endpoint: "diagnostics/activity/getActivity",
|
endpoint: "diagnostics/activity/getActivity",
|
||||||
|
validate: [
|
||||||
|
"headers"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
interface: {
|
interface: {
|
||||||
endpoint: "diagnostics/traffic/interface",
|
endpoint: "diagnostics/traffic/interface",
|
||||||
|
validate: [
|
||||||
|
"interfaces"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user