mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-03 05:32:11 +08:00
* Opnsense widget (#2) * 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 (#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 * Update src/widgets/opnsense/component.jsx Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> * Update public/locales/en/common.json Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> * Update src/widgets/opnsense/component.jsx Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> * Update src/widgets/opnsense/component.jsx Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
import { useTranslation } from "next-i18next";
|
|
|
|
import Container from "components/services/widget/container";
|
|
import Block from "components/services/widget/block";
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
|
|
export default function Component({ service }) {
|
|
const { t } = useTranslation();
|
|
|
|
const { widget } = service;
|
|
|
|
const { data: activityData, error: activityError } = useWidgetAPI(widget, "activity");
|
|
const { data: interfaceData, error: interfaceError } = useWidgetAPI(widget, "interface");
|
|
|
|
if (activityError || interfaceError) {
|
|
const finalError = activityError ?? interfaceError;
|
|
return <Container error={ finalError } />;
|
|
}
|
|
|
|
if (!activityData || !interfaceData) {
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="opnsense.cpu" />
|
|
<Block label="opnsense.memory" />
|
|
<Block label="opnsense.wanUpload" />
|
|
<Block label="opnsense.wanDownload" />
|
|
</Container>
|
|
);
|
|
}
|
|
|
|
|
|
const cpuIdle = activityData.headers[2].match(/ ([0-9.]+)% idle/)[1];
|
|
const cpu = 100 - parseFloat(cpuIdle);
|
|
const memory = activityData.headers[3].match(/Mem: (.+) Active,/)[1];
|
|
|
|
const wanUpload = interfaceData.interfaces.wan['bytes transmitted'];
|
|
const wanDownload = interfaceData.interfaces.wan['bytes received'];
|
|
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="opnsense.cpu" value={t("common.percent", { value: cpu.toFixed(2) })} />
|
|
<Block label="opnsense.memory" value={memory} />
|
|
<Block label="opnsense.wanUpload" value={t("common.bytes", { value: wanUpload })} />
|
|
<Block label="opnsense.wanDownload" value={t("common.bytes", { value: wanDownload })} />
|
|
|
|
</Container>
|
|
);
|
|
}
|