You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
homepage/src/components/widgets/resources/cpu.jsx

53 lines
1.2 KiB

import useSWR from "swr";
import { FiCpu } from "react-icons/fi";
import { useTranslation } from "next-i18next";
import Resource from "../widget/resource";
import Error from "../widget/error";
export default function Cpu({ expanded, refresh = 1500 }) {
const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=cpu`, {
refreshInterval: refresh,
});
if (error || data?.error) {
return <Error />;
}
if (!data) {
return (
<Resource
icon={FiCpu}
value="-"
label={t("resources.cpu")}
expandedValue="-"
expandedLabel={t("resources.load")}
percentage="0"
expanded={expanded}
/>
);
}
return (
<Resource
icon={FiCpu}
value={t("common.number", {
value: data.cpu.usage,
style: "unit",
unit: "percent",
maximumFractionDigits: 0,
})}
label={t("resources.cpu")}
expandedValue={t("common.number", {
value: data.cpu.load,
maximumFractionDigits: 2,
})}
expandedLabel={t("resources.load")}
percentage={data.cpu.usage}
expanded={expanded}
/>
);
}