mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-17 19:16:25 +00:00
Update system-overview.tsx
This commit is contained in:
@@ -225,100 +225,80 @@ export function SystemOverview() {
|
|||||||
const [storageData, setStorageData] = useState<StorageData | null>(null)
|
const [storageData, setStorageData] = useState<StorageData | null>(null)
|
||||||
const [proxmoxStorageData, setProxmoxStorageData] = useState<ProxmoxStorageData | null>(null)
|
const [proxmoxStorageData, setProxmoxStorageData] = useState<ProxmoxStorageData | null>(null)
|
||||||
const [networkData, setNetworkData] = useState<NetworkData | null>(null)
|
const [networkData, setNetworkData] = useState<NetworkData | null>(null)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loadingStates, setLoadingStates] = useState({
|
||||||
|
system: true,
|
||||||
|
vms: true,
|
||||||
|
storage: true,
|
||||||
|
network: true,
|
||||||
|
})
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [networkTimeframe, setNetworkTimeframe] = useState("day")
|
const [networkTimeframe, setNetworkTimeframe] = useState("day")
|
||||||
const [networkTotals, setNetworkTotals] = useState<{ received: number; sent: number }>({ received: 0, sent: 0 })
|
const [networkTotals, setNetworkTotals] = useState<{ received: number; sent: number }>({ received: 0, sent: 0 })
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchAllData = async () => {
|
||||||
try {
|
const [systemResult, vmResult, storageResult, proxmoxStorageResult, networkResult] = await Promise.all([
|
||||||
setLoading(true)
|
fetchSystemData().finally(() => setLoadingStates((prev) => ({ ...prev, system: false }))),
|
||||||
setError(null)
|
fetchVMData().finally(() => setLoadingStates((prev) => ({ ...prev, vms: false }))),
|
||||||
|
Promise.all([fetchStorageData(), fetchProxmoxStorageData()]).finally(() =>
|
||||||
|
setLoadingStates((prev) => ({ ...prev, storage: false })),
|
||||||
|
),
|
||||||
|
fetchNetworkData().finally(() => setLoadingStates((prev) => ({ ...prev, network: false }))),
|
||||||
|
])
|
||||||
|
|
||||||
const systemResult = await fetchSystemData()
|
if (!systemResult) {
|
||||||
|
setError("Flask server not available. Please ensure the server is running.")
|
||||||
if (!systemResult) {
|
return
|
||||||
setError("Flask server not available. Please ensure the server is running.")
|
|
||||||
setLoading(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
setSystemData(systemResult)
|
|
||||||
} catch (err) {
|
|
||||||
console.error("[v0] Error fetching system data:", err)
|
|
||||||
setError("Failed to connect to Flask server. Please check your connection.")
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fetchData()
|
setSystemData(systemResult)
|
||||||
|
|
||||||
const systemInterval = setInterval(() => {
|
|
||||||
fetchSystemData().then((data) => {
|
|
||||||
if (data) setSystemData(data)
|
|
||||||
})
|
|
||||||
}, 9000) // Cambiado de 10000 a 9000ms
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
clearInterval(systemInterval)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchVMs = async () => {
|
|
||||||
const vmResult = await fetchVMData()
|
|
||||||
setVmData(vmResult)
|
setVmData(vmResult)
|
||||||
}
|
setStorageData(storageResult[0])
|
||||||
|
setProxmoxStorageData(storageResult[1])
|
||||||
fetchVMs()
|
|
||||||
const vmInterval = setInterval(fetchVMs, 59000) // Cambiado de 60000 a 59000ms
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
clearInterval(vmInterval)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchStorage = async () => {
|
|
||||||
const storageResult = await fetchStorageData()
|
|
||||||
setStorageData(storageResult)
|
|
||||||
|
|
||||||
const proxmoxStorageResult = await fetchProxmoxStorageData()
|
|
||||||
setProxmoxStorageData(proxmoxStorageResult)
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchStorage()
|
|
||||||
const storageInterval = setInterval(fetchStorage, 59000) // Cambiado de 60000 a 59000ms
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
clearInterval(storageInterval)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchNetwork = async () => {
|
|
||||||
const networkResult = await fetchNetworkData()
|
|
||||||
setNetworkData(networkResult)
|
setNetworkData(networkResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchNetwork()
|
fetchAllData()
|
||||||
const networkInterval = setInterval(fetchNetwork, 59000) // Cambiado de 60000 a 59000ms
|
|
||||||
|
const systemInterval = setInterval(async () => {
|
||||||
|
const data = await fetchSystemData()
|
||||||
|
if (data) setSystemData(data)
|
||||||
|
}, 9000)
|
||||||
|
|
||||||
|
const vmInterval = setInterval(async () => {
|
||||||
|
const data = await fetchVMData()
|
||||||
|
setVmData(data)
|
||||||
|
}, 59000)
|
||||||
|
|
||||||
|
const storageInterval = setInterval(async () => {
|
||||||
|
const [storage, proxmoxStorage] = await Promise.all([fetchStorageData(), fetchProxmoxStorageData()])
|
||||||
|
if (storage) setStorageData(storage)
|
||||||
|
if (proxmoxStorage) setProxmoxStorageData(proxmoxStorage)
|
||||||
|
}, 59000)
|
||||||
|
|
||||||
|
const networkInterval = setInterval(async () => {
|
||||||
|
const data = await fetchNetworkData()
|
||||||
|
if (data) setNetworkData(data)
|
||||||
|
}, 59000)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
clearInterval(systemInterval)
|
||||||
|
clearInterval(vmInterval)
|
||||||
|
clearInterval(storageInterval)
|
||||||
clearInterval(networkInterval)
|
clearInterval(networkInterval)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (loading) {
|
const isInitialLoading = loadingStates.system && !systemData
|
||||||
|
|
||||||
|
if (isInitialLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="text-center py-8">
|
<div className="text-center py-8">
|
||||||
<div className="text-lg font-medium text-foreground mb-2">Connecting to ProxMenux Monitor...</div>
|
<div className="text-lg font-medium text-foreground mb-2">Connecting to ProxMenux Monitor...</div>
|
||||||
<div className="text-sm text-muted-foreground">Fetching real-time system data</div>
|
<div className="text-sm text-muted-foreground">Fetching real-time system data</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3 lg:gap-6">
|
||||||
{[...Array(4)].map((_, i) => (
|
{[...Array(4)].map((_, i) => (
|
||||||
<Card key={i} className="bg-card border-border animate-pulse">
|
<Card key={i} className="bg-card border-border animate-pulse">
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-6">
|
||||||
@@ -386,12 +366,10 @@ export function SystemOverview() {
|
|||||||
|
|
||||||
const formatStorage = (sizeInGB: number): string => {
|
const formatStorage = (sizeInGB: number): string => {
|
||||||
if (sizeInGB < 1) {
|
if (sizeInGB < 1) {
|
||||||
// Less than 1 GB, show in MB
|
|
||||||
return `${(sizeInGB * 1024).toFixed(1)} MB`
|
return `${(sizeInGB * 1024).toFixed(1)} MB`
|
||||||
} else if (sizeInGB > 999) {
|
} else if (sizeInGB > 999) {
|
||||||
return `${(sizeInGB / 1024).toFixed(2)} TB`
|
return `${(sizeInGB / 1024).toFixed(2)} TB`
|
||||||
} else {
|
} else {
|
||||||
// Between 1 and 999 GB, show in GB
|
|
||||||
return `${sizeInGB.toFixed(2)} GB`
|
return `${sizeInGB.toFixed(2)} GB`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -402,13 +380,10 @@ export function SystemOverview() {
|
|||||||
|
|
||||||
const vmLxcStorages = proxmoxStorageData?.storage.filter(
|
const vmLxcStorages = proxmoxStorageData?.storage.filter(
|
||||||
(s) =>
|
(s) =>
|
||||||
// Include only local storage types that can host VMs/LXCs
|
|
||||||
(s.type === "lvm" || s.type === "lvmthin" || s.type === "zfspool" || s.type === "btrfs" || s.type === "dir") &&
|
(s.type === "lvm" || s.type === "lvmthin" || s.type === "zfspool" || s.type === "btrfs" || s.type === "dir") &&
|
||||||
// Exclude network storage
|
|
||||||
s.type !== "nfs" &&
|
s.type !== "nfs" &&
|
||||||
s.type !== "cifs" &&
|
s.type !== "cifs" &&
|
||||||
s.type !== "iscsi" &&
|
s.type !== "iscsi" &&
|
||||||
// Exclude the "local" storage (used for ISOs/templates)
|
|
||||||
s.name !== "local",
|
s.name !== "local",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -474,7 +449,6 @@ export function SystemOverview() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{/* Key Metrics Cards */}
|
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3 lg:gap-6">
|
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3 lg:gap-6">
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
@@ -529,29 +503,37 @@ export function SystemOverview() {
|
|||||||
<Server className="h-4 w-4 text-muted-foreground" />
|
<Server className="h-4 w-4 text-muted-foreground" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-xl lg:text-2xl font-bold text-foreground">{vmStats.running}</div>
|
{loadingStates.vms ? (
|
||||||
<div className="mt-2 flex flex-wrap gap-1">
|
<div className="space-y-2 animate-pulse">
|
||||||
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20">
|
<div className="h-8 bg-muted rounded w-12"></div>
|
||||||
{vmStats.running} Running
|
<div className="h-5 bg-muted rounded w-24"></div>
|
||||||
</Badge>
|
<div className="h-4 bg-muted rounded w-32"></div>
|
||||||
{vmStats.stopped > 0 && (
|
</div>
|
||||||
<Badge variant="outline" className="bg-red-500/10 text-red-500 border-red-500/20">
|
) : (
|
||||||
{vmStats.stopped} Stopped
|
<>
|
||||||
</Badge>
|
<div className="text-xl lg:text-2xl font-bold text-foreground">{vmStats.running}</div>
|
||||||
)}
|
<div className="mt-2 flex flex-wrap gap-1">
|
||||||
</div>
|
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20">
|
||||||
<p className="text-xs text-muted-foreground mt-2">
|
{vmStats.running} Running
|
||||||
Total: {vmStats.vms} VMs, {vmStats.lxc} LXC
|
</Badge>
|
||||||
</p>
|
{vmStats.stopped > 0 && (
|
||||||
|
<Badge variant="outline" className="bg-red-500/10 text-red-500 border-red-500/20">
|
||||||
|
{vmStats.stopped} Stopped
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-muted-foreground mt-2">
|
||||||
|
Total: {vmStats.vms} VMs, {vmStats.lxc} LXC
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Node Metrics Charts */}
|
|
||||||
<NodeMetricsCharts />
|
<NodeMetricsCharts />
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
{/* Storage Summary */}
|
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-foreground flex items-center">
|
<CardTitle className="text-foreground flex items-center">
|
||||||
@@ -560,16 +542,18 @@ export function SystemOverview() {
|
|||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{storageData ? (
|
{loadingStates.storage ? (
|
||||||
|
<div className="space-y-4 animate-pulse">
|
||||||
|
<div className="h-6 bg-muted rounded w-full"></div>
|
||||||
|
<div className="h-4 bg-muted rounded w-3/4"></div>
|
||||||
|
<div className="h-4 bg-muted rounded w-2/3"></div>
|
||||||
|
</div>
|
||||||
|
) : storageData ? (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{(() => {
|
{(() => {
|
||||||
// Calculate total storage across all volumes
|
|
||||||
const totalCapacity = (vmLxcStorageTotal || 0) + (localStorage?.total || 0)
|
const totalCapacity = (vmLxcStorageTotal || 0) + (localStorage?.total || 0)
|
||||||
|
|
||||||
const totalUsed = (vmLxcStorageUsed || 0) + (localStorage?.used || 0)
|
const totalUsed = (vmLxcStorageUsed || 0) + (localStorage?.used || 0)
|
||||||
|
|
||||||
const totalAvailable = (vmLxcStorageAvailable || 0) + (localStorage?.available || 0)
|
const totalAvailable = (vmLxcStorageAvailable || 0) + (localStorage?.available || 0)
|
||||||
|
|
||||||
const totalPercent = totalCapacity > 0 ? (totalUsed / totalCapacity) * 100 : 0
|
const totalPercent = totalCapacity > 0 ? (totalUsed / totalCapacity) * 100 : 0
|
||||||
|
|
||||||
return totalCapacity > 0 ? (
|
return totalCapacity > 0 ? (
|
||||||
@@ -672,7 +656,6 @@ export function SystemOverview() {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* Network Summary */}
|
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-foreground flex items-center justify-between">
|
<CardTitle className="text-foreground flex items-center justify-between">
|
||||||
@@ -695,7 +678,13 @@ export function SystemOverview() {
|
|||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{networkData ? (
|
{loadingStates.network ? (
|
||||||
|
<div className="space-y-4 animate-pulse">
|
||||||
|
<div className="h-6 bg-muted rounded w-full"></div>
|
||||||
|
<div className="h-4 bg-muted rounded w-3/4"></div>
|
||||||
|
<div className="h-4 bg-muted rounded w-2/3"></div>
|
||||||
|
</div>
|
||||||
|
) : networkData ? (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-between items-center pb-3 border-b border-border">
|
<div className="flex justify-between items-center pb-3 border-b border-border">
|
||||||
<span className="text-sm text-muted-foreground">Active Interfaces:</span>
|
<span className="text-sm text-muted-foreground">Active Interfaces:</span>
|
||||||
@@ -766,7 +755,6 @@ export function SystemOverview() {
|
|||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* System Information */}
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -799,7 +787,6 @@ export function SystemOverview() {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* System Health & Alerts */}
|
|
||||||
<Card className="bg-card border-border">
|
<Card className="bg-card border-border">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-foreground flex items-center">
|
<CardTitle className="text-foreground flex items-center">
|
||||||
|
|||||||
Reference in New Issue
Block a user