mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 14:38:47 +00:00
Enhancement: Add configurable refresh interval and max points for glances services (#2363)
--------- Co-authored-by: Quentin de Grandmaison <quentin.degrandmaison@7speaking.com> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
e98b5e2233
commit
c2729e302d
10 changed files with 120 additions and 63 deletions
|
@ -10,18 +10,21 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
|
|||
|
||||
const ChartDual = dynamic(() => import("../components/chart_dual"), { ssr: false });
|
||||
|
||||
const pointsLimit = 15;
|
||||
const defaultPointsLimit = 15;
|
||||
const defaultInterval = (isChart) => (isChart ? 1000 : 5000);
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
const { chart, metric } = widget;
|
||||
const { refreshInterval = defaultInterval(chart), pointsLimit = defaultPointsLimit } = widget;
|
||||
|
||||
const [, interfaceName] = metric.split(":");
|
||||
|
||||
const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ value: 0 }, 0, pointsLimit));
|
||||
|
||||
const { data, error } = useWidgetAPI(widget, "network", {
|
||||
refreshInterval: chart ? 1000 : 5000,
|
||||
refreshInterval: Math.max(defaultInterval(chart), refreshInterval),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -44,7 +47,7 @@ export default function Component({ service }) {
|
|||
});
|
||||
}
|
||||
}
|
||||
}, [data, interfaceName]);
|
||||
}, [data, interfaceName, pointsLimit]);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue