diff --git a/AppImage/components/virtual-machines.tsx b/AppImage/components/virtual-machines.tsx index 7e0d6d7..adf1d95 100644 --- a/AppImage/components/virtual-machines.tsx +++ b/AppImage/components/virtual-machines.tsx @@ -6,7 +6,19 @@ import { Badge } from "./ui/badge" import { Progress } from "./ui/progress" import { Button } from "./ui/button" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog" -import { Server, Play, Square, Cpu, MemoryStick, HardDrive, Network, Power, RotateCcw, StopCircle } from "lucide-react" +import { + Server, + Play, + Square, + Cpu, + MemoryStick, + HardDrive, + Network, + Power, + RotateCcw, + StopCircle, + Container, +} from "lucide-react" import useSWR from "swr" interface VMData { @@ -127,6 +139,18 @@ const formatStorage = (sizeInGB: number): string => { } } +const getUsageColor = (percent: number): string => { + if (percent >= 80) return "text-red-500" + if (percent >= 50) return "text-yellow-500" + return "text-white" +} + +const getProgressColor = (percent: number): string => { + if (percent >= 80) return "[&>div]:bg-red-500" + if (percent >= 50) return "[&>div]:bg-yellow-500" + return "[&>div]:bg-blue-500" +} + export function VirtualMachines() { const { data: vmData, @@ -276,9 +300,17 @@ export function VirtualMachines() { const getTypeBadge = (type: string) => { if (type === "lxc") { - return { color: "bg-cyan-500/10 text-cyan-500 border-cyan-500/20", label: "LXC" } + return { + color: "bg-cyan-500/10 text-cyan-500 border-cyan-500/20", + label: "LXC", + icon: , + } + } + return { + color: "bg-purple-500/10 text-purple-500 border-purple-500/20", + label: "VM", + icon: , } - return { color: "bg-purple-500/10 text-purple-500 border-purple-500/20", label: "VM" } } const safeVMData = vmData || [] @@ -391,7 +423,7 @@ export function VirtualMachines() { {" "} of {physicalMemoryGB.toFixed(1)} GB - + ) : (
@@ -450,107 +482,94 @@ export function VirtualMachines() { {safeVMData.length === 0 ? (
No virtual machines found
) : ( -
+
{safeVMData.map((vm) => { const cpuPercent = (vm.cpu * 100).toFixed(1) const memPercent = vm.maxmem > 0 ? ((vm.mem / vm.maxmem) * 100).toFixed(1) : "0" const memGB = (vm.mem / 1024 ** 3).toFixed(1) const maxMemGB = (vm.maxmem / 1024 ** 3).toFixed(1) + const diskPercent = vm.maxdisk > 0 ? ((vm.disk / vm.maxdisk) * 100).toFixed(1) : "0" + const diskGB = (vm.disk / 1024 ** 3).toFixed(1) + const maxDiskGB = (vm.maxdisk / 1024 ** 3).toFixed(1) const typeBadge = getTypeBadge(vm.type) const lxcIP = vm.type === "lxc" ? vmConfigs[vm.vmid] : null return (
handleVMClick(vm)} > -
-
- -
-
- {vm.name} - - {typeBadge.label} - -
-
-
ID: {vm.vmid}
- {lxcIP && ( - <> - -
- - - IP: {lxcIP} - -
- - )} -
-
+
+
+ + {getStatusIcon(vm.status)} + {vm.status.toUpperCase()} + + + {typeBadge.icon} + {typeBadge.label} + + {vm.name} + ID: {vm.vmid} + {lxcIP && ( + + + {lxcIP} + + )} + Uptime: {formatUptime(vm.uptime)}
- - - {getStatusIcon(vm.status)} - {vm.status.toUpperCase()} -
-
+
-
CPU Usage
-
{cpuPercent}%
- +
CPU Usage
+
+ {cpuPercent}% +
+
-
Memory Usage
-
+
Memory
+
{memGB} / {maxMemGB} GB
- +
-
-
Disk I/O
-
-
- - ↓ {formatBytes(vm.diskread)} -
-
- - ↑ {formatBytes(vm.diskwrite)} -
+
+
Disk Usage
+
+ {diskGB} / {maxDiskGB} GB
+
-
-
Network I/O
-
+
+
Network I/O
+
- ↓ {formatBytes(vm.netin)}
-
- +
↑ {formatBytes(vm.netout)}
- -
-
Uptime
-
{formatUptime(vm.uptime)}
-
) })} @@ -576,6 +595,7 @@ export function VirtualMachines() { {selectedVM && (
+ {getTypeBadge(selectedVM.type).icon} {getTypeBadge(selectedVM.type).label} @@ -604,37 +624,37 @@ export function VirtualMachines() {
CPU Usage
-
80 - ? "text-red-500" - : selectedVM.cpu * 100 > 60 - ? "text-yellow-500" - : "text-green-500" - }`} - > +
{(selectedVM.cpu * 100).toFixed(1)}%
+
Memory
80 - ? "text-red-500" - : (selectedVM.mem / selectedVM.maxmem) * 100 > 60 - ? "text-yellow-500" - : "text-blue-500" - }`} + className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`} > {(selectedVM.mem / 1024 ** 3).toFixed(1)} / {(selectedVM.maxmem / 1024 ** 3).toFixed(1)} GB
+
Disk
-
+
{(selectedVM.disk / 1024 ** 3).toFixed(1)} / {(selectedVM.maxdisk / 1024 ** 3).toFixed(1)} GB
+
Uptime