Update AppImage

This commit is contained in:
MacRimi
2025-10-19 17:29:23 +02:00
parent f662ce0b7a
commit c305ef1360
2 changed files with 405 additions and 404 deletions

View File

@@ -1,64 +1,67 @@
"use client" "use client"
import { useState, useEffect } from "react" import { useState, useEffect } from "react"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { ArrowLeft, Loader2 } from "lucide-react" import { ArrowLeft, Loader2 } from "lucide-react"
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from "recharts" import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from "recharts"
interface MetricsDialogProps { interface MetricsViewProps {
open: boolean
onClose: () => void
vmid: number vmid: number
vmName: string vmName: string
vmType: "qemu" | "lxc" vmType: "qemu" | "lxc"
metricType: "cpu" | "memory" | "network" | "disk" metricType: "cpu" | "memory" | "network" | "disk"
onBack: () => void
} }
const TIMEFRAME_OPTIONS = [ const TIMEFRAME_OPTIONS = [
{ value: "hour", label: "1 Hora" }, { value: "hour", label: "1 Hour" },
{ value: "day", label: "24 Horas" }, { value: "day", label: "24 Hours" },
{ value: "week", label: "7 Días" }, { value: "week", label: "7 Days" },
{ value: "month", label: "30 Días" }, { value: "month", label: "30 Days" },
{ value: "year", label: "1 Año" }, { value: "year", label: "1 Year" },
] ]
const METRIC_TITLES = { const METRIC_TITLES = {
cpu: "Uso de CPU", cpu: "CPU Usage",
memory: "Uso de Memoria", memory: "Memory Usage",
network: "Tráfico de Red", network: "Network Traffic",
disk: "I/O de Disco", disk: "Disk I/O",
} }
export function MetricsDialog({ open, onClose, vmid, vmName, vmType, metricType }: MetricsDialogProps) { export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: MetricsViewProps) {
const [timeframe, setTimeframe] = useState("week") const [timeframe, setTimeframe] = useState("week")
const [data, setData] = useState<any[]>([]) const [data, setData] = useState<any[]>([])
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
useEffect(() => { useEffect(() => {
if (open) { fetchMetrics()
fetchMetrics() }, [vmid, timeframe])
}
}, [open, vmid, timeframe])
const fetchMetrics = async () => { const fetchMetrics = async () => {
setLoading(true) setLoading(true)
setError(null) setError(null)
console.log("[v0] Fetching metrics for VMID:", vmid, "Timeframe:", timeframe, "Type:", vmType)
try { try {
const response = await fetch(`http://localhost:8008/api/vms/${vmid}/metrics?timeframe=${timeframe}`) const response = await fetch(`http://localhost:8008/api/vms/${vmid}/metrics?timeframe=${timeframe}`)
console.log("[v0] Response status:", response.status)
if (!response.ok) { if (!response.ok) {
throw new Error("Failed to fetch metrics") const errorData = await response.json()
console.error("[v0] Error response:", errorData)
throw new Error(errorData.error || "Failed to fetch metrics")
} }
const result = await response.json() const result = await response.json()
console.log("[v0] Metrics data received:", result)
// Transform data for charts // Transform data for charts
const transformedData = result.data.map((item: any) => ({ const transformedData = result.data.map((item: any) => ({
time: new Date(item.time * 1000).toLocaleString("es-ES", { time: new Date(item.time * 1000).toLocaleString("en-US", {
month: "short", month: "short",
day: "numeric", day: "numeric",
hour: timeframe === "hour" ? "2-digit" : undefined, hour: timeframe === "hour" ? "2-digit" : undefined,
@@ -75,10 +78,11 @@ export function MetricsDialog({ open, onClose, vmid, vmName, vmType, metricType
diskwrite: item.diskwrite ? (item.diskwrite / 1024 / 1024).toFixed(2) : 0, diskwrite: item.diskwrite ? (item.diskwrite / 1024 / 1024).toFixed(2) : 0,
})) }))
console.log("[v0] Transformed data:", transformedData.length, "points")
setData(transformedData) setData(transformedData)
} catch (err) { } catch (err: any) {
console.error("[v0] Error fetching metrics:", err) console.error("[v0] Error fetching metrics:", err)
setError("Error al cargar las métricas") setError(err.message || "Error loading metrics")
} finally { } finally {
setLoading(false) setLoading(false)
} }
@@ -104,7 +108,7 @@ export function MetricsDialog({ open, onClose, vmid, vmName, vmType, metricType
if (data.length === 0) { if (data.length === 0) {
return ( return (
<div className="flex items-center justify-center h-96"> <div className="flex items-center justify-center h-96">
<p className="text-muted-foreground">No hay datos disponibles</p> <p className="text-muted-foreground">No data available</p>
</div> </div>
) )
} }
@@ -139,7 +143,7 @@ export function MetricsDialog({ open, onClose, vmid, vmName, vmType, metricType
labelStyle={{ color: "hsl(var(--foreground))" }} labelStyle={{ color: "hsl(var(--foreground))" }}
/> />
<Legend /> <Legend />
<Line type="monotone" dataKey="memory" stroke="#10b981" name="Memoria %" strokeWidth={2} dot={false} /> <Line type="monotone" dataKey="memory" stroke="#10b981" name="Memory %" strokeWidth={2} dot={false} />
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>
) )
@@ -159,8 +163,8 @@ export function MetricsDialog({ open, onClose, vmid, vmName, vmType, metricType
labelStyle={{ color: "hsl(var(--foreground))" }} labelStyle={{ color: "hsl(var(--foreground))" }}
/> />
<Legend /> <Legend />
<Line type="monotone" dataKey="netin" stroke="#3b82f6" name="Entrada (MB)" strokeWidth={2} dot={false} /> <Line type="monotone" dataKey="netin" stroke="#3b82f6" name="In (MB)" strokeWidth={2} dot={false} />
<Line type="monotone" dataKey="netout" stroke="#8b5cf6" name="Salida (MB)" strokeWidth={2} dot={false} /> <Line type="monotone" dataKey="netout" stroke="#8b5cf6" name="Out (MB)" strokeWidth={2} dot={false} />
</LineChart> </LineChart>
</ResponsiveContainer> </ResponsiveContainer>
) )
@@ -180,19 +184,12 @@ export function MetricsDialog({ open, onClose, vmid, vmName, vmType, metricType
labelStyle={{ color: "hsl(var(--foreground))" }} labelStyle={{ color: "hsl(var(--foreground))" }}
/> />
<Legend /> <Legend />
<Line <Line type="monotone" dataKey="diskread" stroke="#10b981" name="Read (MB)" strokeWidth={2} dot={false} />
type="monotone"
dataKey="diskread"
stroke="#10b981"
name="Lectura (MB)"
strokeWidth={2}
dot={false}
/>
<Line <Line
type="monotone" type="monotone"
dataKey="diskwrite" dataKey="diskwrite"
stroke="#f59e0b" stroke="#f59e0b"
name="Escritura (MB)" name="Write (MB)"
strokeWidth={2} strokeWidth={2}
dot={false} dot={false}
/> />
@@ -203,42 +200,40 @@ export function MetricsDialog({ open, onClose, vmid, vmName, vmType, metricType
} }
return ( return (
<Dialog open={open} onOpenChange={onClose}> <div className="flex flex-col h-full">
<DialogContent className="max-w-4xl max-h-[90vh] flex flex-col p-0"> {/* Fixed Header */}
{/* Fixed Header */} <div className="p-6 pb-4 border-b shrink-0">
<DialogHeader className="p-6 pb-4 border-b"> <div className="flex items-center justify-between">
<div className="flex items-center justify-between"> <div className="flex items-center gap-3">
<div className="flex items-center gap-3"> <Button variant="ghost" size="icon" onClick={onBack}>
<Button variant="ghost" size="icon" onClick={onClose}> <ArrowLeft className="h-5 w-5" />
<ArrowLeft className="h-5 w-5" /> </Button>
</Button> <div>
<div> <h2 className="text-xl font-semibold">
<DialogTitle className="text-xl"> {METRIC_TITLES[metricType]} - {vmName}
{METRIC_TITLES[metricType]} - {vmName} </h2>
</DialogTitle> <p className="text-sm text-muted-foreground mt-1">
<p className="text-sm text-muted-foreground mt-1"> VMID: {vmid} Type: {vmType.toUpperCase()}
VMID: {vmid} Tipo: {vmType.toUpperCase()} </p>
</p>
</div>
</div> </div>
<Select value={timeframe} onValueChange={setTimeframe}>
<SelectTrigger className="w-32">
<SelectValue />
</SelectTrigger>
<SelectContent>
{TIMEFRAME_OPTIONS.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div> </div>
</DialogHeader> <Select value={timeframe} onValueChange={setTimeframe}>
<SelectTrigger className="w-32">
<SelectValue />
</SelectTrigger>
<SelectContent>
{TIMEFRAME_OPTIONS.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
{/* Scrollable Content */} {/* Scrollable Content */}
<div className="flex-1 overflow-y-auto p-6">{renderChart()}</div> <div className="flex-1 overflow-y-auto p-6">{renderChart()}</div>
</DialogContent> </div>
</Dialog>
) )
} }

View File

@@ -20,7 +20,7 @@ import {
Container, Container,
} from "lucide-react" } from "lucide-react"
import useSWR from "swr" import useSWR from "swr"
import { MetricsDialog } from "./metrics-dialog" import { MetricsView } from "./metrics-dialog"
interface VMData { interface VMData {
vmid: number vmid: number
@@ -185,8 +185,9 @@ export function VirtualMachines() {
const [controlLoading, setControlLoading] = useState(false) const [controlLoading, setControlLoading] = useState(false)
const [detailsLoading, setDetailsLoading] = useState(false) const [detailsLoading, setDetailsLoading] = useState(false)
const [vmConfigs, setVmConfigs] = useState<Record<number, string>>({}) const [vmConfigs, setVmConfigs] = useState<Record<number, string>>({})
const [metricsDialogOpen, setMetricsDialogOpen] = useState(false) const [currentView, setCurrentView] = useState<"main" | "metrics">("main")
const [selectedMetric, setSelectedMetric] = useState<"cpu" | "memory" | "disk" | "network" | null>(null) const [selectedMetric, setSelectedMetric] = useState<"cpu" | "memory" | "disk" | "network" | null>(null)
const [metricsDialogOpen, setMetricsDialogOpen] = useState(false) // Declare and initialize metricsDialogOpen
useEffect(() => { useEffect(() => {
const fetchLXCIPs = async () => { const fetchLXCIPs = async () => {
@@ -219,6 +220,8 @@ export function VirtualMachines() {
const handleVMClick = async (vm: VMData) => { const handleVMClick = async (vm: VMData) => {
setSelectedVM(vm) setSelectedVM(vm)
setCurrentView("main")
setSelectedMetric(null)
setDetailsLoading(true) setDetailsLoading(true)
try { try {
const response = await fetch(`/api/vms/${vm.vmid}`) const response = await fetch(`/api/vms/${vm.vmid}`)
@@ -233,6 +236,17 @@ export function VirtualMachines() {
} }
} }
const handleMetricClick = (metric: "cpu" | "memory" | "disk" | "network") => {
setSelectedMetric(metric)
setCurrentView("metrics")
setMetricsDialogOpen(true) // Open the metrics dialog
}
const handleBackToMain = () => {
setCurrentView("main")
setSelectedMetric(null)
}
const handleVMControl = async (vmid: number, action: string) => { const handleVMControl = async (vmid: number, action: string) => {
setControlLoading(true) setControlLoading(true)
try { try {
@@ -707,368 +721,360 @@ export function VirtualMachines() {
onOpenChange={() => { onOpenChange={() => {
setSelectedVM(null) setSelectedVM(null)
setVMDetails(null) setVMDetails(null)
setCurrentView("main")
setSelectedMetric(null)
setMetricsDialogOpen(false) // Close the metrics dialog when the VM dialog is closed
}} }}
> >
<DialogContent className="max-w-4xl max-h-[95vh] flex flex-col p-0"> <DialogContent className="max-w-4xl max-h-[95vh] flex flex-col p-0">
<DialogHeader className="pb-4 border-b border-border px-6 pt-6"> {currentView === "main" ? (
<DialogTitle className="flex flex-col sm:flex-row sm:items-center gap-3"> <>
<div className="flex items-center gap-2"> <DialogHeader className="pb-4 border-b border-border px-6 pt-6">
<Server className="h-5 w-5 flex-shrink-0" /> <DialogTitle className="flex flex-col sm:flex-row sm:items-center gap-3">
<span className="text-lg truncate">{selectedVM?.name}</span> <div className="flex items-center gap-2">
</div> <Server className="h-5 w-5 flex-shrink-0" />
{selectedVM && ( <span className="text-lg truncate">{selectedVM?.name}</span>
<div className="flex items-center gap-2 flex-wrap">
<Badge variant="outline" className={`${getTypeBadge(selectedVM.type).color} flex-shrink-0`}>
{getTypeBadge(selectedVM.type).icon}
{getTypeBadge(selectedVM.type).label}
</Badge>
<Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
{selectedVM.status.toUpperCase()}
</Badge>
</div>
)}
</DialogTitle>
</DialogHeader>
<div className="flex-1 overflow-y-auto px-6 py-4">
<div className="space-y-6">
{selectedVM && (
<>
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Basic Information
</h3>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
<div>
<div className="text-xs text-muted-foreground mb-1">Name</div>
<div className="font-semibold text-foreground">{selectedVM.name}</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">VMID</div>
<div className="font-semibold text-foreground">{selectedVM.vmid}</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">CPU Usage</div>
<div
className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => {
setSelectedMetric("cpu")
setMetricsDialogOpen(true)
}}
>
<div className={`font-semibold mb-1 ${getUsageColor(selectedVM.cpu * 100)}`}>
{(selectedVM.cpu * 100).toFixed(1)}%
</div>
<Progress
value={selectedVM.cpu * 100}
className={`h-1.5 ${getModalProgressColor(selectedVM.cpu * 100)}`}
/>
</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Memory</div>
<div
className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => {
setSelectedMetric("memory")
setMetricsDialogOpen(true)
}}
>
<div
className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
>
{(selectedVM.mem / 1024 ** 3).toFixed(1)} / {(selectedVM.maxmem / 1024 ** 3).toFixed(1)} GB
</div>
<Progress
value={(selectedVM.mem / selectedVM.maxmem) * 100}
className={`h-1.5 ${getModalProgressColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
/>
</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Disk</div>
<div
className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => {
setSelectedMetric("disk")
setMetricsDialogOpen(true)
}}
>
<div
className={`font-semibold mb-1 ${getUsageColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
>
{(selectedVM.disk / 1024 ** 3).toFixed(1)} / {(selectedVM.maxdisk / 1024 ** 3).toFixed(1)}{" "}
GB
</div>
<Progress
value={(selectedVM.disk / selectedVM.maxdisk) * 100}
className={`h-1.5 ${getModalProgressColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
/>
</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Uptime</div>
<div className="font-semibold text-foreground">{formatUptime(selectedVM.uptime)}</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
<div
className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => {
setSelectedMetric("disk")
setMetricsDialogOpen(true)
}}
>
<div className="text-sm text-green-500 flex items-center gap-1">
<span></span>
<span>{((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
<div className="text-sm text-blue-500 flex items-center gap-1">
<span></span>
<span>{((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Network I/O</div>
<div
className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => {
setSelectedMetric("network")
setMetricsDialogOpen(true)
}}
>
<div className="text-sm text-green-500 flex items-center gap-1">
<span></span>
<span>{((selectedVM.netin || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
<div className="text-sm text-blue-500 flex items-center gap-1">
<span></span>
<span>{((selectedVM.netout || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
</div>
</div>
</div>
</div> </div>
{selectedVM && (
<div className="flex items-center gap-2 flex-wrap">
<Badge variant="outline" className={`${getTypeBadge(selectedVM.type).color} flex-shrink-0`}>
{getTypeBadge(selectedVM.type).icon}
{getTypeBadge(selectedVM.type).label}
</Badge>
<Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
{selectedVM.status.toUpperCase()}
</Badge>
</div>
)}
</DialogTitle>
</DialogHeader>
{detailsLoading ? ( <div className="flex-1 overflow-y-auto px-6 py-4">
<div className="text-center py-8 text-muted-foreground">Loading configuration...</div> <div className="space-y-6">
) : vmDetails?.config ? ( {selectedVM && (
<> <>
<div> <div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide"> <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Resources Basic Information
</h3> </h3>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4"> <div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
{vmDetails.config.cores && ( <div>
<div> <div className="text-xs text-muted-foreground mb-1">Name</div>
<div className="text-xs text-muted-foreground mb-1">CPU Cores</div> <div className="font-semibold text-foreground">{selectedVM.name}</div>
<div className="font-semibold text-blue-500">{vmDetails.config.cores}</div> </div>
<div>
<div className="text-xs text-muted-foreground mb-1">VMID</div>
<div className="font-semibold text-foreground">{selectedVM.vmid}</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">CPU Usage</div>
<div
className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleMetricClick("cpu")}
>
<div className={`font-semibold mb-1 ${getUsageColor(selectedVM.cpu * 100)}`}>
{(selectedVM.cpu * 100).toFixed(1)}%
</div>
<Progress
value={selectedVM.cpu * 100}
className={`h-1.5 ${getModalProgressColor(selectedVM.cpu * 100)}`}
/>
</div> </div>
)} </div>
{vmDetails.config.sockets && ( <div>
<div> <div className="text-xs text-muted-foreground mb-1">Memory</div>
<div className="text-xs text-muted-foreground mb-1">CPU Sockets</div> <div
<div className="font-semibold text-foreground">{vmDetails.config.sockets}</div> className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleMetricClick("memory")}
>
<div
className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
>
{(selectedVM.mem / 1024 ** 3).toFixed(1)} / {(selectedVM.maxmem / 1024 ** 3).toFixed(1)}{" "}
GB
</div>
<Progress
value={(selectedVM.mem / selectedVM.maxmem) * 100}
className={`h-1.5 ${getModalProgressColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
/>
</div> </div>
)} </div>
{vmDetails.config.memory && ( <div>
<div> <div className="text-xs text-muted-foreground mb-1">Disk</div>
<div className="text-xs text-muted-foreground mb-1">Memory</div> <div
<div className="font-semibold text-blue-500">{vmDetails.config.memory} MB</div> className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleMetricClick("disk")}
>
<div
className={`font-semibold mb-1 ${getUsageColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
>
{(selectedVM.disk / 1024 ** 3).toFixed(1)} /{" "}
{(selectedVM.maxdisk / 1024 ** 3).toFixed(1)} GB
</div>
<Progress
value={(selectedVM.disk / selectedVM.maxdisk) * 100}
className={`h-1.5 ${getModalProgressColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
/>
</div> </div>
)} </div>
{vmDetails.config.swap && ( <div>
<div> <div className="text-xs text-muted-foreground mb-1">Uptime</div>
<div className="text-xs text-muted-foreground mb-1">Swap</div> <div className="font-semibold text-foreground">{formatUptime(selectedVM.uptime)}</div>
<div className="font-semibold text-foreground">{vmDetails.config.swap} MB</div> </div>
</div> <div>
)} <div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
{vmDetails.config.rootfs && ( <div
<div className="col-span-2 lg:col-span-3"> className="cursor-pointer hover:opacity-80 transition-opacity"
<div className="text-xs text-muted-foreground mb-1">Root Filesystem</div> onClick={() => handleMetricClick("disk")}
<div className="font-medium text-foreground text-sm break-all font-mono"> >
{vmDetails.config.rootfs} <div className="text-sm text-green-500 flex items-center gap-1">
<span></span>
<span>{((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
<div className="text-sm text-blue-500 flex items-center gap-1">
<span></span>
<span>{((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div> </div>
</div> </div>
)} </div>
{Object.keys(vmDetails.config) <div>
.filter((key) => key.match(/^(scsi|sata|ide|virtio)\d+$/)) <div className="text-xs text-muted-foreground mb-1">Network I/O</div>
.map((diskKey) => ( <div
<div key={diskKey} className="col-span-2 lg:col-span-3"> className="cursor-pointer hover:opacity-80 transition-opacity"
<div className="text-xs text-muted-foreground mb-1"> onClick={() => handleMetricClick("network")}
{diskKey.toUpperCase().replace(/(\d+)/, " $1")} >
</div> <div className="text-sm text-green-500 flex items-center gap-1">
<div className="font-medium text-foreground text-sm break-all font-mono"> <span></span>
{vmDetails.config[diskKey]} <span>{((selectedVM.netin || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
</div> </div>
))} <div className="text-sm text-blue-500 flex items-center gap-1">
<span></span>
<span>{((selectedVM.netout || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
</div>
</div>
</div> </div>
</div> </div>
<div> {detailsLoading ? (
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide"> <div className="text-center py-8 text-muted-foreground">Loading configuration...</div>
Network ) : vmDetails?.config ? (
</h3> <>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4"> <div>
{Object.keys(vmDetails.config) <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
.filter((key) => key.match(/^net\d+$/)) Resources
.map((netKey) => ( </h3>
<div key={netKey} className="col-span-1"> <div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
<div className="text-xs text-muted-foreground mb-1"> {vmDetails.config.cores && (
Network Interface {netKey.replace("net", "")} <div>
<div className="text-xs text-muted-foreground mb-1">CPU Cores</div>
<div className="font-semibold text-blue-500">{vmDetails.config.cores}</div>
</div> </div>
<div className="font-medium text-green-500 text-sm break-all font-mono"> )}
{vmDetails.config[netKey]} {vmDetails.config.sockets && (
<div>
<div className="text-xs text-muted-foreground mb-1">CPU Sockets</div>
<div className="font-semibold text-foreground">{vmDetails.config.sockets}</div>
</div> </div>
</div> )}
))} {vmDetails.config.memory && (
{vmDetails.config.nameserver && ( <div>
<div> <div className="text-xs text-muted-foreground mb-1">Memory</div>
<div className="text-xs text-muted-foreground mb-1">DNS Nameserver</div> <div className="font-semibold text-blue-500">{vmDetails.config.memory} MB</div>
<div className="font-medium text-foreground font-mono">{vmDetails.config.nameserver}</div> </div>
)}
{vmDetails.config.swap && (
<div>
<div className="text-xs text-muted-foreground mb-1">Swap</div>
<div className="font-semibold text-foreground">{vmDetails.config.swap} MB</div>
</div>
)}
{vmDetails.config.rootfs && (
<div className="col-span-2 lg:col-span-3">
<div className="text-xs text-muted-foreground mb-1">Root Filesystem</div>
<div className="font-medium text-foreground text-sm break-all font-mono">
{vmDetails.config.rootfs}
</div>
</div>
)}
{Object.keys(vmDetails.config)
.filter((key) => key.match(/^(scsi|sata|ide|virtio)\d+$/))
.map((diskKey) => (
<div key={diskKey} className="col-span-2 lg:col-span-3">
<div className="text-xs text-muted-foreground mb-1">
{diskKey.toUpperCase().replace(/(\d+)/, " $1")}
</div>
<div className="font-medium text-foreground text-sm break-all font-mono">
{vmDetails.config[diskKey]}
</div>
</div>
))}
</div> </div>
)} </div>
{vmDetails.config.searchdomain && (
<div>
<div className="text-xs text-muted-foreground mb-1">Search Domain</div>
<div className="font-medium text-foreground">{vmDetails.config.searchdomain}</div>
</div>
)}
{vmDetails.config.hostname && (
<div>
<div className="text-xs text-muted-foreground mb-1">Hostname</div>
<div className="font-medium text-foreground">{vmDetails.config.hostname}</div>
</div>
)}
</div>
</div>
<div> <div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide"> <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Options Network
</h3> </h3>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4"> <div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
{vmDetails.config.onboot !== undefined && ( {Object.keys(vmDetails.config)
<div> .filter((key) => key.match(/^net\d+$/))
<div className="text-xs text-muted-foreground mb-1">Start on Boot</div> .map((netKey) => (
<Badge <div key={netKey} className="col-span-1">
variant="outline" <div className="text-xs text-muted-foreground mb-1">
className={ Network Interface {netKey.replace("net", "")}
vmDetails.config.onboot </div>
? "bg-green-500/10 text-green-500 border-green-500/20" <div className="font-medium text-green-500 text-sm break-all font-mono">
: "bg-red-500/10 text-red-500 border-red-500/20" {vmDetails.config[netKey]}
} </div>
> </div>
{vmDetails.config.onboot ? "Yes" : "No"} ))}
</Badge> {vmDetails.config.nameserver && (
<div>
<div className="text-xs text-muted-foreground mb-1">DNS Nameserver</div>
<div className="font-medium text-foreground font-mono">
{vmDetails.config.nameserver}
</div>
</div>
)}
{vmDetails.config.searchdomain && (
<div>
<div className="text-xs text-muted-foreground mb-1">Search Domain</div>
<div className="font-medium text-foreground">{vmDetails.config.searchdomain}</div>
</div>
)}
{vmDetails.config.hostname && (
<div>
<div className="text-xs text-muted-foreground mb-1">Hostname</div>
<div className="font-medium text-foreground">{vmDetails.config.hostname}</div>
</div>
)}
</div> </div>
)} </div>
{vmDetails.config.unprivileged !== undefined && (
<div> <div>
<div className="text-xs text-muted-foreground mb-1">Unprivileged</div> <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
<Badge Options
variant="outline" </h3>
className={ <div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
vmDetails.config.unprivileged {vmDetails.config.onboot !== undefined && (
? "bg-green-500/10 text-green-500 border-green-500/20" <div>
: "bg-yellow-500/10 text-yellow-500 border-yellow-500/20" <div className="text-xs text-muted-foreground mb-1">Start on Boot</div>
} <Badge
> variant="outline"
{vmDetails.config.unprivileged ? "Yes" : "No"} className={
</Badge> vmDetails.config.onboot
? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-red-500/10 text-red-500 border-red-500/20"
}
>
{vmDetails.config.onboot ? "Yes" : "No"}
</Badge>
</div>
)}
{vmDetails.config.unprivileged !== undefined && (
<div>
<div className="text-xs text-muted-foreground mb-1">Unprivileged</div>
<Badge
variant="outline"
className={
vmDetails.config.unprivileged
? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-yellow-500/10 text-yellow-500 border-yellow-500/20"
}
>
{vmDetails.config.unprivileged ? "Yes" : "No"}
</Badge>
</div>
)}
{vmDetails.config.ostype && (
<div>
<div className="text-xs text-muted-foreground mb-1">OS Type</div>
<div className="font-medium text-foreground">{vmDetails.config.ostype}</div>
</div>
)}
{vmDetails.config.arch && (
<div>
<div className="text-xs text-muted-foreground mb-1">Architecture</div>
<div className="font-medium text-foreground">{vmDetails.config.arch}</div>
</div>
)}
{vmDetails.config.boot && (
<div>
<div className="text-xs text-muted-foreground mb-1">Boot Order</div>
<div className="font-medium text-foreground">{vmDetails.config.boot}</div>
</div>
)}
{vmDetails.config.features && (
<div className="col-span-2 lg:col-span-3">
<div className="text-xs text-muted-foreground mb-1">Features</div>
<div className="font-medium text-foreground text-sm">{vmDetails.config.features}</div>
</div>
)}
</div> </div>
)} </div>
{vmDetails.config.ostype && ( </>
<div> ) : null}
<div className="text-xs text-muted-foreground mb-1">OS Type</div>
<div className="font-medium text-foreground">{vmDetails.config.ostype}</div>
</div>
)}
{vmDetails.config.arch && (
<div>
<div className="text-xs text-muted-foreground mb-1">Architecture</div>
<div className="font-medium text-foreground">{vmDetails.config.arch}</div>
</div>
)}
{vmDetails.config.boot && (
<div>
<div className="text-xs text-muted-foreground mb-1">Boot Order</div>
<div className="font-medium text-foreground">{vmDetails.config.boot}</div>
</div>
)}
{vmDetails.config.features && (
<div className="col-span-2 lg:col-span-3">
<div className="text-xs text-muted-foreground mb-1">Features</div>
<div className="font-medium text-foreground text-sm">{vmDetails.config.features}</div>
</div>
)}
</div>
</div>
</> </>
) : null} )}
</> </div>
)} </div>
</div>
</div>
<div className="border-t border-border bg-background px-6 py-4 mt-auto"> <div className="border-t border-border bg-background px-6 py-4 mt-auto">
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide"> <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Control Actions Control Actions
</h3> </h3>
<div className="grid grid-cols-2 gap-3"> <div className="grid grid-cols-2 gap-3">
<Button <Button
className="w-full bg-green-600 hover:bg-green-700 text-white" className="w-full bg-green-600 hover:bg-green-700 text-white"
disabled={selectedVM?.status === "running" || controlLoading} disabled={selectedVM?.status === "running" || controlLoading}
onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "start")} onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "start")}
> >
<Play className="h-4 w-4 mr-2" /> <Play className="h-4 w-4 mr-2" />
Start Start
</Button> </Button>
<Button <Button
className="w-full bg-blue-600 hover:bg-blue-700 text-white" className="w-full bg-blue-600 hover:bg-blue-700 text-white"
disabled={selectedVM?.status !== "running" || controlLoading} disabled={selectedVM?.status !== "running" || controlLoading}
onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "shutdown")} onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "shutdown")}
> >
<Power className="h-4 w-4 mr-2" /> <Power className="h-4 w-4 mr-2" />
Shutdown Shutdown
</Button> </Button>
<Button <Button
className="w-full bg-blue-600 hover:bg-blue-700 text-white" className="w-full bg-blue-600 hover:bg-blue-700 text-white"
disabled={selectedVM?.status !== "running" || controlLoading} disabled={selectedVM?.status !== "running" || controlLoading}
onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "reboot")} onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "reboot")}
> >
<RotateCcw className="h-4 w-4 mr-2" /> <RotateCcw className="h-4 w-4 mr-2" />
Reboot Reboot
</Button> </Button>
<Button <Button
className="w-full bg-blue-600 hover:bg-blue-700 text-white" className="w-full bg-blue-600 hover:bg-blue-700 text-white"
disabled={selectedVM?.status !== "running" || controlLoading} disabled={selectedVM?.status !== "running" || controlLoading}
onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "stop")} onClick={() => selectedVM && handleVMControl(selectedVM.vmid, "stop")}
> >
<StopCircle className="h-4 w-4 mr-2" /> <StopCircle className="h-4 w-4 mr-2" />
Force Stop Force Stop
</Button> </Button>
</div> </div>
</div> </div>
</>
) : (
/* Render metrics view when currentView is "metrics" */
selectedVM &&
selectedMetric && (
<MetricsView
vmid={selectedVM.vmid}
vmName={selectedVM.name}
vmType={selectedVM.type as "qemu" | "lxc"}
metricType={selectedMetric}
onBack={handleBackToMain}
/>
)
)}
</DialogContent> </DialogContent>
</Dialog> </Dialog>
{/* MetricsDialog component usage */}
{selectedVM && selectedMetric && (
<MetricsDialog
open={metricsDialogOpen}
onClose={() => {
setMetricsDialogOpen(false)
setSelectedMetric(null)
}}
vmid={selectedVM.vmid}
vmName={selectedVM.name}
vmType={selectedVM.type}
metricType={selectedMetric}
/>
)}
</div> </div>
) )
} }