Update AppImage

This commit is contained in:
MacRimi
2025-10-20 22:15:08 +02:00
parent 6479f14d3d
commit deae081cb3
2 changed files with 297 additions and 124 deletions

View File

@@ -43,19 +43,27 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
setLoading(true) setLoading(true)
setError(null) setError(null)
console.log("[v0] Fetching metrics for VMID:", vmid, "Timeframe:", timeframe, "Type:", vmType)
try { try {
const baseUrl = const baseUrl =
typeof window !== "undefined" ? `${window.location.protocol}//${window.location.hostname}:8008` : "" typeof window !== "undefined" ? `${window.location.protocol}//${window.location.hostname}:8008` : ""
const apiUrl = `${baseUrl}/api/vms/${vmid}/metrics?timeframe=${timeframe}` const apiUrl = `${baseUrl}/api/vms/${vmid}/metrics?timeframe=${timeframe}`
console.log("[v0] Fetching from URL:", apiUrl)
const response = await fetch(apiUrl) const response = await fetch(apiUrl)
console.log("[v0] Response status:", response.status)
if (!response.ok) { if (!response.ok) {
const errorData = await response.json() const errorData = await response.json()
console.error("[v0] Error response:", errorData)
throw new Error(errorData.error || "Failed to fetch metrics") 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)
const transformedData = result.data.map((item: any) => { const transformedData = result.data.map((item: any) => {
const date = new Date(item.time * 1000) const date = new Date(item.time * 1000)
@@ -113,8 +121,10 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
} }
}) })
console.log("[v0] Transformed data:", transformedData.length, "points")
setData(transformedData) setData(transformedData)
} catch (err: any) { } catch (err: any) {
console.error("[v0] Error fetching metrics:", err)
setError(err.message || "Error loading metrics") setError(err.message || "Error loading metrics")
} finally { } finally {
setLoading(false) setLoading(false)
@@ -156,7 +166,9 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
switch (metricType) { switch (metricType) {
case "cpu": case "cpu":
const maxCpuValue = Math.max(...data.map((d) => d.cpu || 0)) const maxCpuValue = Math.max(...data.map((d) => d.cpu || 0))
const cpuDomainMax = Math.ceil(maxCpuValue * 1.15) const cpuDomainMax = Math.ceil(maxCpuValue * 1.15) // 15% margin
console.log("[v0] CPU - Max value:", maxCpuValue, "Domain max:", cpuDomainMax, "Data points:", data.length)
console.log("[v0] CPU - Sample data:", data.slice(0, 3))
return ( return (
<ResponsiveContainer width="100%" height={400}> <ResponsiveContainer width="100%" height={400}>
@@ -204,7 +216,16 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
case "memory": case "memory":
const maxMemoryValue = Math.max(...data.map((d) => d.memory || 0)) const maxMemoryValue = Math.max(...data.map((d) => d.memory || 0))
const memoryDomainMax = Math.ceil(maxMemoryValue * 1.15) const memoryDomainMax = Math.ceil(maxMemoryValue * 1.15) // 15% margin
console.log(
"[v0] Memory - Max value:",
maxMemoryValue,
"Domain max:",
memoryDomainMax,
"Data points:",
data.length,
)
console.log("[v0] Memory - Sample data:", data.slice(0, 3))
return ( return (
<ResponsiveContainer width="100%" height={400}> <ResponsiveContainer width="100%" height={400}>
@@ -252,7 +273,24 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
case "network": case "network":
const maxNetworkValue = Math.max(...data.map((d) => Math.max(d.netin || 0, d.netout || 0))) const maxNetworkValue = Math.max(...data.map((d) => Math.max(d.netin || 0, d.netout || 0)))
const networkDomainMax = Math.ceil(maxNetworkValue * 1.15) const networkDomainMax = Math.ceil(maxNetworkValue * 1.15) // 15% margin
console.log(
"[v0] Network - Max value:",
maxNetworkValue,
"Domain max:",
networkDomainMax,
"Data points:",
data.length,
)
console.log("[v0] Network - Sample data:", data.slice(0, 3))
console.log(
"[v0] Network - All netin values:",
data.map((d) => d.netin),
)
console.log(
"[v0] Network - All netout values:",
data.map((d) => d.netout),
)
return ( return (
<ResponsiveContainer width="100%" height={400}> <ResponsiveContainer width="100%" height={400}>
@@ -309,7 +347,9 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
case "disk": case "disk":
const maxDiskValue = Math.max(...data.map((d) => Math.max(d.diskread || 0, d.diskwrite || 0))) const maxDiskValue = Math.max(...data.map((d) => Math.max(d.diskread || 0, d.diskwrite || 0)))
const diskDomainMax = Math.ceil(maxDiskValue * 1.15) const diskDomainMax = Math.ceil(maxDiskValue * 1.15) // 15% margin
console.log("[v0] Disk - Max value:", maxDiskValue, "Domain max:", diskDomainMax, "Data points:", data.length)
console.log("[v0] Disk - Sample data:", data.slice(0, 3))
return ( return (
<ResponsiveContainer width="100%" height={400}> <ResponsiveContainer width="100%" height={400}>

View File

@@ -381,6 +381,12 @@ export function VirtualMachines() {
return "text-green-500" return "text-green-500"
} }
console.log("[v0] Memory status:", {
physical: physicalMemoryGB,
allocated: allocatedMemoryGB,
isOvercommit: isMemoryOvercommit,
})
if (isLoading) { if (isLoading) {
return ( return (
<div className="space-y-6"> <div className="space-y-6">
@@ -717,8 +723,35 @@ export function VirtualMachines() {
<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">
{currentView === "main" ? ( {currentView === "main" ? (
<> <>
<DialogHeader className="pb-4 border-b border-border px-6 pt-6 shrink-0"> <DialogHeader className="pb-4 border-b border-border px-6 pt-6 sticky top-0 bg-background z-10">
<DialogTitle className="flex flex-col sm:flex-row sm:items-center gap-3"> <DialogTitle className="flex flex-col sm:flex-row sm:items-center gap-3">
{/* Desktop layout */}
<div className="hidden sm:flex items-center gap-3 flex-wrap">
<div className="flex items-center gap-2">
<Server className="h-5 w-5 flex-shrink-0" />
<span className="text-lg truncate">{selectedVM?.name}</span>
<span className="text-sm text-muted-foreground">ID: {selectedVM?.vmid}</span>
</div>
{selectedVM && (
<>
<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>
{selectedVM.status === "running" && (
<span className="text-sm text-muted-foreground">
Uptime: {formatUptime(selectedVM.uptime)}
</span>
)}
</>
)}
</div>
{/* Mobile layout */}
<div className="flex sm:hidden flex-col gap-2">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Server className="h-5 w-5 flex-shrink-0" /> <Server className="h-5 w-5 flex-shrink-0" />
<span className="text-lg truncate">{selectedVM?.name}</span> <span className="text-lg truncate">{selectedVM?.name}</span>
@@ -734,10 +767,13 @@ export function VirtualMachines() {
{selectedVM.status.toUpperCase()} {selectedVM.status.toUpperCase()}
</Badge> </Badge>
{selectedVM.status === "running" && ( {selectedVM.status === "running" && (
<span className="text-sm text-muted-foreground">Uptime: {formatUptime(selectedVM.uptime)}</span> <span className="text-sm text-muted-foreground">
Uptime: {formatUptime(selectedVM.uptime)}
</span>
)} )}
</div> </div>
)} )}
</div>
</DialogTitle> </DialogTitle>
</DialogHeader> </DialogHeader>
@@ -745,18 +781,17 @@ export function VirtualMachines() {
<div className="space-y-6"> <div className="space-y-6">
{selectedVM && ( {selectedVM && (
<> <>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> <div>
{/* CPU & Memory Card */} <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
<div Basic Information
className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors cursor-pointer sm:hover:shadow-md" </h3>
onClick={() => handleMetricClick("cpu")} <div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
>
<h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
CPU & Memory
</h4>
<div className="space-y-3">
<div> <div>
<div className="text-xs text-muted-foreground mb-1">CPU Usage</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)}`}> <div className={`font-semibold mb-1 ${getUsageColor(selectedVM.cpu * 100)}`}>
{(selectedVM.cpu * 100).toFixed(1)}% {(selectedVM.cpu * 100).toFixed(1)}%
</div> </div>
@@ -765,8 +800,13 @@ export function VirtualMachines() {
className={`h-1.5 ${getModalProgressColor(selectedVM.cpu * 100)}`} className={`h-1.5 ${getModalProgressColor(selectedVM.cpu * 100)}`}
/> />
</div> </div>
</div>
<div> <div>
<div className="text-xs text-muted-foreground mb-1">Memory</div> <div className="text-xs text-muted-foreground mb-1">Memory</div>
<div
className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleMetricClick("memory")}
>
<div <div
className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`} className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
> >
@@ -779,19 +819,12 @@ export function VirtualMachines() {
/> />
</div> </div>
</div> </div>
</div> <div>
<div className="text-xs text-muted-foreground mb-1">Disk</div>
{/* Disk Usage Card */}
<div <div
className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors cursor-pointer sm:hover:shadow-md" className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleMetricClick("disk")} onClick={() => handleMetricClick("disk")}
> >
<h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Disk Usage
</h4>
<div className="space-y-3">
<div>
<div className="text-xs text-muted-foreground mb-1">Storage</div>
<div <div
className={`font-semibold mb-1 ${getUsageColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`} className={`font-semibold mb-1 ${getUsageColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
> >
@@ -804,91 +837,190 @@ export function VirtualMachines() {
/> />
</div> </div>
</div> </div>
</div> <div>
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
{/* Disk I/O Card */}
<div <div
className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors cursor-pointer sm:hover:shadow-md" className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleMetricClick("disk")} onClick={() => handleMetricClick("disk")}
> >
<h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Disk I/O
</h4>
<div className="space-y-2">
<div className="text-sm text-green-500 flex items-center gap-1"> <div className="text-sm text-green-500 flex items-center gap-1">
<span> Read</span> <span></span>
<span className="ml-auto font-semibold"> <span>{((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB</span>
{((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB
</span>
</div> </div>
<div className="text-sm text-blue-500 flex items-center gap-1"> <div className="text-sm text-blue-500 flex items-center gap-1">
<span> Write</span> <span></span>
<span className="ml-auto font-semibold"> <span>{((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB</span>
{((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB
</span>
</div> </div>
</div> </div>
</div> </div>
<div>
{/* Network I/O Card */} <div className="text-xs text-muted-foreground mb-1">Network I/O</div>
<div <div
className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors cursor-pointer sm:hover:shadow-md" className="cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleMetricClick("network")} onClick={() => handleMetricClick("network")}
> >
<h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Network I/O
</h4>
<div className="space-y-2">
<div className="text-sm text-green-500 flex items-center gap-1"> <div className="text-sm text-green-500 flex items-center gap-1">
<span> Download</span> <span></span>
<span className="ml-auto font-semibold"> <span>{((selectedVM.netin || 0) / 1024 ** 2).toFixed(2)} MB</span>
{((selectedVM.netin || 0) / 1024 ** 2).toFixed(2)} MB
</span>
</div> </div>
<div className="text-sm text-blue-500 flex items-center gap-1"> <div className="text-sm text-blue-500 flex items-center gap-1">
<span> Upload</span> <span></span>
<span className="ml-auto font-semibold"> <span>{((selectedVM.netout || 0) / 1024 ** 2).toFixed(2)} MB</span>
{((selectedVM.netout || 0) / 1024 ** 2).toFixed(2)} MB </div>
</span> </div>
</div> </div>
</div> </div>
</div> </div>
{/* Resources & Configuration Card */} <div>
<div className="p-4 rounded-lg border border-border bg-card sm:col-span-2 lg:col-span-3"> <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
<h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide"> Resources
Configuration </h3>
</h4> <div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
{detailsLoading ? ( {vmDetails?.config.cores && (
<div className="text-center py-4 text-muted-foreground">Loading configuration...</div>
) : vmDetails?.config ? (
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
{vmDetails.config.cores && (
<div> <div>
<div className="text-xs text-muted-foreground mb-1">CPU Cores</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 className="font-semibold text-blue-500">{vmDetails.config.cores}</div>
</div> </div>
)} )}
{vmDetails.config.memory && ( {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>
)}
{vmDetails?.config.memory && (
<div> <div>
<div className="text-xs text-muted-foreground mb-1">Memory</div> <div className="text-xs text-muted-foreground mb-1">Memory</div>
<div className="font-semibold text-blue-500">{vmDetails.config.memory} MB</div> <div className="font-semibold text-blue-500">{vmDetails.config.memory} MB</div>
</div> </div>
)} )}
{vmDetails.config.swap && ( {vmDetails?.config.swap && (
<div> <div>
<div className="text-xs text-muted-foreground mb-1">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 className="font-semibold text-foreground">{vmDetails.config.swap} MB</div>
</div> </div>
)} )}
{vmDetails.config.ostype && ( {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>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Network
</h3>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
{Object.keys(vmDetails?.config || {})
.filter((key) => key.match(/^net\d+$/))
.map((netKey) => (
<div key={netKey} className="col-span-1">
<div className="text-xs text-muted-foreground mb-1">
Network Interface {netKey.replace("net", "")}
</div>
<div className="font-medium text-green-500 text-sm break-all font-mono">
{vmDetails?.config[netKey]}
</div>
</div>
))}
{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>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Options
</h3>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
{vmDetails?.config.onboot !== undefined && (
<div>
<div className="text-xs text-muted-foreground mb-1">Start on Boot</div>
<Badge
variant="outline"
className={
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>
<div className="text-xs text-muted-foreground mb-1">OS Type</div> <div className="text-xs text-muted-foreground mb-1">OS Type</div>
<div className="font-medium text-foreground">{vmDetails.config.ostype}</div> <div className="font-medium text-foreground">{vmDetails.config.ostype}</div>
</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> </div>
) : null} )}
{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> </div>
</> </>
@@ -896,7 +1028,7 @@ export function VirtualMachines() {
</div> </div>
</div> </div>
<div className="border-t border-border bg-background px-6 py-4 shrink-0"> <div className="border-t border-border bg-background px-6 py-4 sticky bottom-0">
<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>
@@ -937,6 +1069,7 @@ export function VirtualMachines() {
</div> </div>
</> </>
) : ( ) : (
/* Render metrics view when currentView is "metrics" */
selectedVM && selectedVM &&
selectedMetric && ( selectedMetric && (
<MetricsView <MetricsView