import useSWR from "swr";
import { FaMemory } from "react-icons/fa";
import { BiError } from "react-icons/bi";
import { useTranslation } from "next-i18next";
import UsageBar from "./usage-bar";
export default function Memory({ expanded }) {
const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=memory`, {
refreshInterval: 1500,
});
if (error || data?.error) {
return (
);
}
if (!data) {
return (
-
{t("resources.free")}
{expanded && (
-
{t("resources.total")}
)}
);
}
const percent = Math.round((data.memory.usedMemMb / data.memory.totalMemMb) * 100);
return (
{t("common.bytes", { value: data.memory.freeMemMb * 1024 * 1024, maximumFractionDigits: 1, binary: true })}
{t("resources.free")}
{expanded && (
{t("common.bytes", {
value: data.memory.totalMemMb * 1024 * 1024,
maximumFractionDigits: 1,
binary: true,
})}
{t("resources.total")}
)}
);
}