diff --git a/AppImage/components/virtual-machines.tsx b/AppImage/components/virtual-machines.tsx index 11cb10b..0a092e7 100644 --- a/AppImage/components/virtual-machines.tsx +++ b/AppImage/components/virtual-machines.tsx @@ -83,7 +83,7 @@ const fetcher = async (url: string) => { } const data = await response.json() - return Array.isArray(data) ? data : [] + return data } const formatBytes = (bytes: number | undefined): string => { @@ -286,34 +286,34 @@ export function VirtualMachines() { return (safeVMData.reduce((sum, vm) => sum + (vm.maxmem || 0), 0) / 1024 ** 3).toFixed(1) }, [safeVMData]) - const { data: systemData } = useSWR("/api/system", fetcher, { - refreshInterval: 30000, - revalidateOnFocus: false, + const { data: systemData } = useSWR<{ memory_total: number; memory_used: number; memory_usage: number }>( + "/api/system", + fetcher, + { + refreshInterval: 30000, + revalidateOnFocus: false, + }, + ) + + const physicalMemoryGB = systemData?.memory_total ?? null + const usedMemoryGB = systemData?.memory_used ?? null + const memoryUsagePercent = systemData?.memory_usage ?? null + const allocatedMemoryGB = Number.parseFloat(totalAllocatedMemoryGB) + const isMemoryOvercommit = physicalMemoryGB !== null && allocatedMemoryGB > physicalMemoryGB + + const getMemoryUsageColor = (percent: number | null) => { + if (percent === null) return "bg-blue-500" + if (percent >= 80) return "bg-red-500" + if (percent >= 60) return "bg-yellow-500" + return "bg-green-500" + } + + console.log("[v0] Memory status:", { + physical: physicalMemoryGB, + allocated: allocatedMemoryGB, + isOvercommit: isMemoryOvercommit, }) - const physicalMemoryGB = useMemo(() => { - if (systemData && systemData.memory_total) { - console.log("[v0] Physical memory GB:", systemData.memory_total) - return systemData.memory_total.toFixed(1) - } - console.log("[v0] No physical memory data available") - return null - }, [systemData]) - - const isMemoryOvercommit = useMemo(() => { - if (physicalMemoryGB) { - const overcommit = Number.parseFloat(totalAllocatedMemoryGB) > Number.parseFloat(physicalMemoryGB) - console.log("[v0] Memory overcommit check:", { - allocated: totalAllocatedMemoryGB, - physical: physicalMemoryGB, - isOvercommit: overcommit, - }) - return overcommit - } - console.log("[v0] Cannot check overcommit - no physical memory data") - return false - }, [totalAllocatedMemoryGB, physicalMemoryGB]) - if (isLoading) { return (
- {isMemoryOvercommit ? `Excede memoria fĂsica (${physicalMemoryGB} GB)` : "Allocated RAM"} -
+ + {/* Allocated RAM (configured) */} +