* chore: update core services and module export * Correct version of plugins (#374) Co-authored-by: Hien To <tominhhien97@gmail.com> * janhq/jan: Update tag build 1.0.2 for data-plugin * janhq/jan: Update tag build 1.0.2 for inference-plugin * janhq/jan: Update tag build 1.0.2 for model-management-plugin * janhq/jan: Update tag build 1.0.2 for monitoring-plugin * janhq/jan: Update tag build 1.0.2 for openai-plugin * chore: update web to use @janhq/core module --------- Co-authored-by: hiento09 <136591877+hiento09@users.noreply.github.com> Co-authored-by: Hien To <tominhhien97@gmail.com> Co-authored-by: Service Account <service@jan.ai>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { executeSerial } from "../../../electron/core/plugin-manager/execution/extension-manager";
|
|
import { SystemMonitoringService } from "@janhq/core";
|
|
|
|
export default function useGetSystemResources() {
|
|
const [ram, setRam] = useState<number>(0);
|
|
const [cpu, setCPU] = useState<number>(0);
|
|
|
|
const getSystemResources = async () => {
|
|
const resourceInfor = await executeSerial(
|
|
SystemMonitoringService.GetResourcesInfo
|
|
);
|
|
const currentLoadInfor = await executeSerial(
|
|
SystemMonitoringService.GetCurrentLoad
|
|
);
|
|
const ram =
|
|
(resourceInfor?.mem?.active ?? 0) / (resourceInfor?.mem?.total ?? 1);
|
|
setRam(Math.round(ram * 100));
|
|
setCPU(Math.round(currentLoadInfor?.currentLoad ?? 0));
|
|
};
|
|
|
|
useEffect(() => {
|
|
getSystemResources();
|
|
|
|
// Fetch interval - every 3s
|
|
const intervalId = setInterval(() => {
|
|
getSystemResources();
|
|
}, 3000);
|
|
|
|
// clean up
|
|
return () => clearInterval(intervalId);
|
|
}, []);
|
|
|
|
return {
|
|
ram,
|
|
cpu,
|
|
};
|
|
}
|