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, backend }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/${backend || 'resources'}?type=memory`, { refreshInterval: 1500, }); if (error || data?.error) { return (
{t("widget.api_error")}
); } 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: 0, binary: true })}
{t("resources.free")}
{expanded && (
{t("common.bytes", { value: data.memory.totalMemMb * 1024 * 1024, maximumFractionDigits: 0, binary: true, })}
{t("resources.total")}
)}
); }