Update AppImage

This commit is contained in:
MacRimi
2025-10-20 20:56:54 +02:00
parent 60707c3868
commit 6479f14d3d
2 changed files with 94 additions and 253 deletions

View File

@@ -43,27 +43,19 @@ 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)
@@ -121,10 +113,8 @@ 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)
@@ -166,9 +156,7 @@ 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) // 15% margin const cpuDomainMax = Math.ceil(maxCpuValue * 1.15)
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}>
@@ -216,16 +204,7 @@ 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) // 15% margin const memoryDomainMax = Math.ceil(maxMemoryValue * 1.15)
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}>
@@ -273,24 +252,7 @@ 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) // 15% margin const networkDomainMax = Math.ceil(maxNetworkValue * 1.15)
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}>
@@ -347,9 +309,7 @@ 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) // 15% margin const diskDomainMax = Math.ceil(maxDiskValue * 1.15)
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,12 +381,6 @@ 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">
@@ -723,11 +717,12 @@ 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"> <DialogHeader className="pb-4 border-b border-border px-6 pt-6 shrink-0">
<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">
<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>
<span className="text-sm text-muted-foreground">ID: {selectedVM?.vmid}</span>
</div> </div>
{selectedVM && ( {selectedVM && (
<div className="flex items-center gap-2 flex-wrap"> <div className="flex items-center gap-2 flex-wrap">
@@ -738,6 +733,9 @@ export function VirtualMachines() {
<Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}> <Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
{selectedVM.status.toUpperCase()} {selectedVM.status.toUpperCase()}
</Badge> </Badge>
{selectedVM.status === "running" && (
<span className="text-sm text-muted-foreground">Uptime: {formatUptime(selectedVM.uptime)}</span>
)}
</div> </div>
)} )}
</DialogTitle> </DialogTitle>
@@ -747,25 +745,18 @@ export function VirtualMachines() {
<div className="space-y-6"> <div className="space-y-6">
{selectedVM && ( {selectedVM && (
<> <>
<div> <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide"> {/* CPU & Memory Card */}
Basic Information <div
</h3> className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors cursor-pointer sm:hover:shadow-md"
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4"> onClick={() => handleMetricClick("cpu")}
<div> >
<div className="text-xs text-muted-foreground mb-1">Name</div> <h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
<div className="font-semibold text-foreground">{selectedVM.name}</div> CPU & Memory
</div> </h4>
<div> <div className="space-y-3">
<div className="text-xs text-muted-foreground mb-1">VMID</div> <div>
<div className="font-semibold text-foreground">{selectedVM.vmid}</div> <div className="text-xs text-muted-foreground mb-1">CPU Usage</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)}`}> <div className={`font-semibold mb-1 ${getUsageColor(selectedVM.cpu * 100)}`}>
{(selectedVM.cpu * 100).toFixed(1)}% {(selectedVM.cpu * 100).toFixed(1)}%
</div> </div>
@@ -774,13 +765,8 @@ 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)}`}
> >
@@ -793,12 +779,19 @@ export function VirtualMachines() {
/> />
</div> </div>
</div> </div>
<div> </div>
<div className="text-xs text-muted-foreground mb-1">Disk</div>
<div {/* Disk Usage Card */}
className="cursor-pointer hover:opacity-80 transition-opacity" <div
onClick={() => handleMetricClick("disk")} className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors cursor-pointer sm:hover:shadow-md"
> 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)}`}
> >
@@ -811,66 +804,71 @@ export function VirtualMachines() {
/> />
</div> </div>
</div> </div>
<div> </div>
<div className="text-xs text-muted-foreground mb-1">Uptime</div>
<div className="font-semibold text-foreground">{formatUptime(selectedVM.uptime)}</div> {/* Disk I/O Card */}
</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"
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div> onClick={() => handleMetricClick("disk")}
<div >
className="cursor-pointer hover:opacity-80 transition-opacity" <h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
onClick={() => handleMetricClick("disk")} Disk I/O
> </h4>
<div className="text-sm text-green-500 flex items-center gap-1"> <div className="space-y-2">
<span></span> <div className="text-sm text-green-500 flex items-center gap-1">
<span>{((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB</span> <span> Read</span>
</div> <span className="ml-auto font-semibold">
<div className="text-sm text-blue-500 flex items-center gap-1"> {((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB
<span></span> </span>
<span>{((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB</span>
</div>
</div> </div>
</div> <div className="text-sm text-blue-500 flex items-center gap-1">
<div> <span> Write</span>
<div className="text-xs text-muted-foreground mb-1">Network I/O</div> <span className="ml-auto font-semibold">
<div {((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB
className="cursor-pointer hover:opacity-80 transition-opacity" </span>
onClick={() => handleMetricClick("network")}
>
<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> </div>
</div>
{detailsLoading ? ( {/* Network I/O Card */}
<div className="text-center py-8 text-muted-foreground">Loading configuration...</div> <div
) : vmDetails?.config ? ( className="p-4 rounded-lg border border-border bg-card hover:bg-accent/50 transition-colors cursor-pointer sm:hover:shadow-md"
<> onClick={() => handleMetricClick("network")}
<div> >
<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 Network I/O
</h3> </h4>
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4"> <div className="space-y-2">
<div className="text-sm text-green-500 flex items-center gap-1">
<span> Download</span>
<span className="ml-auto font-semibold">
{((selectedVM.netin || 0) / 1024 ** 2).toFixed(2)} MB
</span>
</div>
<div className="text-sm text-blue-500 flex items-center gap-1">
<span> Upload</span>
<span className="ml-auto font-semibold">
{((selectedVM.netout || 0) / 1024 ** 2).toFixed(2)} MB
</span>
</div>
</div>
</div>
{/* Resources & Configuration Card */}
<div className="p-4 rounded-lg border border-border bg-card sm:col-span-2 lg:col-span-3">
<h4 className="text-xs font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Configuration
</h4>
{detailsLoading ? (
<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 && ( {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.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 && ( {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>
@@ -883,138 +881,22 @@ export function VirtualMachines() {
<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.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 && ( {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>
)}
{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> ) : null}
</> </div>
) : null} </div>
</> </>
)} )}
</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 shrink-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>
@@ -1055,7 +937,6 @@ export function VirtualMachines() {
</div> </div>
</> </>
) : ( ) : (
/* Render metrics view when currentView is "metrics" */
selectedVM && selectedVM &&
selectedMetric && ( selectedMetric && (
<MetricsView <MetricsView