Files
ProxMenux/AppImage/components/network-metrics.tsx

709 lines
31 KiB
TypeScript
Raw Normal View History

2025-09-28 23:09:31 +02:00
"use client"
2025-10-04 19:25:28 +02:00
import { useState } from "react"
2025-09-28 23:09:31 +02:00
import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"
import { Badge } from "./ui/badge"
2025-10-04 19:05:39 +02:00
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog"
import { Wifi, Globe, Shield, Activity, Network, Router, AlertCircle, Zap } from "lucide-react"
2025-10-04 19:25:28 +02:00
import useSWR from "swr"
2025-09-28 23:09:31 +02:00
2025-09-30 00:09:11 +02:00
interface NetworkData {
2025-10-04 20:06:47 +02:00
physical_interfaces?: NetworkInterface[]
bridge_interfaces?: NetworkInterface[]
2025-10-04 19:25:28 +02:00
vm_lxc_interfaces?: NetworkInterface[]
2025-09-30 00:09:11 +02:00
traffic: {
bytes_sent: number
bytes_recv: number
packets_sent?: number
packets_recv?: number
2025-10-04 19:25:28 +02:00
packet_loss_in?: number
packet_loss_out?: number
2025-10-04 19:58:12 +02:00
dropin?: number
dropout?: number
2025-09-30 00:09:11 +02:00
}
2025-10-04 20:06:47 +02:00
physical_active_count?: number
physical_total_count?: number
bridge_active_count?: number
bridge_total_count?: number
2025-10-04 19:25:28 +02:00
vm_lxc_active_count?: number
vm_lxc_total_count?: number
2025-09-30 00:09:11 +02:00
}
interface NetworkInterface {
name: string
2025-10-04 19:05:39 +02:00
type: string
2025-09-30 00:09:11 +02:00
status: string
2025-10-04 19:05:39 +02:00
speed: number
duplex: string
mtu: number
mac_address: string | null
2025-09-30 00:09:11 +02:00
addresses: Array<{
ip: string
netmask: string
}>
2025-10-04 19:05:39 +02:00
bytes_sent?: number
bytes_recv?: number
packets_sent?: number
packets_recv?: number
errors_in?: number
errors_out?: number
drops_in?: number
drops_out?: number
bond_mode?: string
bond_slaves?: string[]
bond_active_slave?: string | null
bridge_members?: string[]
2025-10-04 19:25:28 +02:00
packet_loss_in?: number
packet_loss_out?: number
vmid?: number
vm_name?: string
vm_type?: string
vm_status?: string
2025-10-04 19:05:39 +02:00
}
const getInterfaceTypeBadge = (type: string) => {
switch (type) {
case "physical":
return { color: "bg-blue-500/10 text-blue-500 border-blue-500/20", label: "Physical" }
case "bridge":
return { color: "bg-green-500/10 text-green-500 border-green-500/20", label: "Bridge" }
case "bond":
return { color: "bg-purple-500/10 text-purple-500 border-purple-500/20", label: "Bond" }
case "vlan":
return { color: "bg-cyan-500/10 text-cyan-500 border-cyan-500/20", label: "VLAN" }
2025-10-04 19:58:12 +02:00
case "vm_lxc":
return { color: "bg-orange-500/10 text-orange-500 border-orange-500/20", label: "Virtual" }
case "virtual":
return { color: "bg-orange-500/10 text-orange-500 border-orange-500/20", label: "Virtual" }
2025-10-04 19:05:39 +02:00
default:
return { color: "bg-gray-500/10 text-gray-500 border-gray-500/20", label: "Unknown" }
}
}
2025-10-04 19:25:28 +02:00
const getVMTypeBadge = (vmType: string | undefined) => {
if (vmType === "lxc") {
return { color: "bg-cyan-500/10 text-cyan-500 border-cyan-500/20", label: "LXC" }
} else if (vmType === "vm") {
return { color: "bg-purple-500/10 text-purple-500 border-purple-500/20", label: "VM" }
}
return { color: "bg-gray-500/10 text-gray-500 border-gray-500/20", label: "Unknown" }
}
2025-10-04 19:05:39 +02:00
const formatBytes = (bytes: number | undefined): string => {
if (!bytes || bytes === 0) return "0 B"
const k = 1024
const sizes = ["B", "KB", "MB", "GB", "TB"]
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`
}
const formatSpeed = (speed: number): string => {
if (speed === 0) return "N/A"
if (speed >= 1000) return `${(speed / 1000).toFixed(1)} Gbps`
return `${speed} Mbps`
2025-09-30 00:09:11 +02:00
}
2025-09-28 23:09:31 +02:00
2025-10-04 19:25:28 +02:00
const fetcher = async (url: string): Promise<NetworkData> => {
2025-10-04 19:58:12 +02:00
const response = await fetch(url, {
2025-10-04 19:25:28 +02:00
method: "GET",
headers: {
"Content-Type": "application/json",
},
signal: AbortSignal.timeout(5000),
})
if (!response.ok) {
throw new Error(`Flask server responded with status: ${response.status}`)
2025-09-30 00:09:11 +02:00
}
2025-10-04 19:25:28 +02:00
return response.json()
2025-09-30 00:09:11 +02:00
}
2025-09-28 23:09:31 +02:00
export function NetworkMetrics() {
2025-10-04 19:25:28 +02:00
const {
data: networkData,
error,
isLoading,
} = useSWR<NetworkData>("/api/network", fetcher, {
2025-10-04 19:58:12 +02:00
refreshInterval: 30000, // Refresh every 30 seconds
2025-10-04 19:25:28 +02:00
revalidateOnFocus: false,
revalidateOnReconnect: true,
})
2025-09-30 00:09:11 +02:00
2025-10-04 19:25:28 +02:00
const [selectedInterface, setSelectedInterface] = useState<NetworkInterface | null>(null)
2025-09-30 00:09:11 +02:00
2025-10-04 19:25:28 +02:00
if (isLoading) {
2025-09-30 00:09:11 +02:00
return (
<div className="space-y-6">
<div className="text-center py-8">
<div className="text-lg font-medium text-foreground mb-2">Loading network data...</div>
</div>
</div>
)
}
if (error || !networkData) {
return (
<div className="space-y-6">
<Card className="bg-red-500/10 border-red-500/20">
<CardContent className="p-6">
<div className="flex items-center gap-3 text-red-600">
<AlertCircle className="h-6 w-6" />
<div>
<div className="font-semibold text-lg mb-1">Flask Server Not Available</div>
<div className="text-sm">
2025-10-04 19:25:28 +02:00
{error?.message ||
"Unable to connect to the Flask server. Please ensure the server is running and try again."}
2025-09-30 00:09:11 +02:00
</div>
</div>
</div>
</CardContent>
</Card>
</div>
)
}
2025-10-04 19:25:28 +02:00
const trafficInGB = (networkData.traffic.bytes_recv / 1024 ** 3).toFixed(2)
const trafficOutGB = (networkData.traffic.bytes_sent / 1024 ** 3).toFixed(2)
const packetsRecvK = networkData.traffic.packets_recv ? (networkData.traffic.packets_recv / 1000).toFixed(0) : "0"
2025-09-30 00:09:11 +02:00
2025-09-28 23:09:31 +02:00
return (
<div className="space-y-6">
{/* Network Overview Cards */}
2025-10-04 19:25:28 +02:00
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 md:gap-6">
2025-09-28 23:09:31 +02:00
<Card className="bg-card border-border">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Network Traffic</CardTitle>
<Activity className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
2025-10-04 19:25:28 +02:00
<div className="text-2xl font-bold text-foreground">{trafficInGB} GB</div>
<div className="flex flex-wrap items-center gap-2 mt-2">
<span className="text-xs text-green-500"> {trafficInGB} GB</span>
<span className="text-xs text-blue-500"> {trafficOutGB} GB</span>
2025-09-28 23:09:31 +02:00
</div>
2025-09-30 00:09:11 +02:00
<p className="text-xs text-muted-foreground mt-2">Total data transferred</p>
2025-09-28 23:09:31 +02:00
</CardContent>
</Card>
<Card className="bg-card border-border">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
2025-09-30 00:09:11 +02:00
<CardTitle className="text-sm font-medium text-muted-foreground">Active Interfaces</CardTitle>
2025-09-28 23:09:31 +02:00
<Network className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
2025-10-04 20:06:47 +02:00
<div className="text-2xl font-bold text-foreground">
{(networkData.physical_active_count ?? 0) + (networkData.bridge_active_count ?? 0)}
</div>
<div className="flex flex-wrap items-center gap-2 mt-2">
<Badge variant="outline" className="bg-blue-500/10 text-blue-500 border-blue-500/20 text-xs">
Physical: {networkData.physical_active_count ?? 0}/{networkData.physical_total_count ?? 0}
</Badge>
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20 text-xs">
Bridges: {networkData.bridge_active_count ?? 0}/{networkData.bridge_total_count ?? 0}
2025-10-04 19:58:12 +02:00
</Badge>
2025-09-28 23:09:31 +02:00
</div>
2025-10-04 20:06:47 +02:00
<p className="text-xs text-muted-foreground mt-2">
{(networkData.physical_total_count ?? 0) + (networkData.bridge_total_count ?? 0)} total interfaces
</p>
2025-09-28 23:09:31 +02:00
</CardContent>
</Card>
<Card className="bg-card border-border">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Firewall Status</CardTitle>
<Shield className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-foreground">Active</div>
<div className="flex items-center mt-2">
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20">
Protected
</Badge>
</div>
2025-09-30 00:09:11 +02:00
<p className="text-xs text-muted-foreground mt-2">System protected</p>
2025-09-28 23:09:31 +02:00
</CardContent>
</Card>
<Card className="bg-card border-border">
2025-10-04 19:25:28 +02:00
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Packets</CardTitle>
<Globe className="h-4 w-4 text-muted-foreground" />
2025-09-28 23:09:31 +02:00
</CardHeader>
<CardContent>
2025-10-04 19:25:28 +02:00
<div className="text-2xl font-bold text-foreground">{packetsRecvK}K</div>
2025-09-28 23:09:31 +02:00
<div className="flex items-center mt-2">
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20">
2025-09-30 00:09:11 +02:00
Received
2025-09-28 23:09:31 +02:00
</Badge>
</div>
2025-10-04 19:25:28 +02:00
{networkData.traffic.packet_loss_in !== undefined && networkData.traffic.packet_loss_in > 0 && (
<p className="text-xs text-yellow-500 mt-2">Loss: {networkData.traffic.packet_loss_in}%</p>
)}
{(!networkData.traffic.packet_loss_in || networkData.traffic.packet_loss_in === 0) && (
<p className="text-xs text-muted-foreground mt-2">No packet loss</p>
)}
2025-09-28 23:09:31 +02:00
</CardContent>
</Card>
</div>
2025-10-04 20:06:47 +02:00
{networkData.physical_interfaces && networkData.physical_interfaces.length > 0 && (
<Card className="bg-card border-border">
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Router className="h-5 w-5 mr-2" />
Physical Interfaces
<Badge variant="outline" className="ml-3 bg-blue-500/10 text-blue-500 border-blue-500/20">
{networkData.physical_active_count ?? 0} / {networkData.physical_total_count ?? 0} Active
</Badge>
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
{networkData.physical_interfaces.map((interface_, index) => {
const typeBadge = getInterfaceTypeBadge(interface_.type)
return (
<div
key={index}
className="flex flex-col gap-3 p-4 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer"
onClick={() => setSelectedInterface(interface_)}
>
{/* First row: Icon, Name, Type Badge, Status */}
<div className="flex items-center gap-3 flex-wrap">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="flex items-center gap-2 min-w-0">
<div className="font-medium text-foreground">{interface_.name}</div>
<Badge variant="outline" className={typeBadge.color}>
{typeBadge.label}
</Badge>
</div>
<Badge
variant="outline"
className={
interface_.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20 ml-auto"
: "bg-red-500/10 text-red-500 border-red-500/20 ml-auto"
}
>
{interface_.status.toUpperCase()}
2025-10-04 19:05:39 +02:00
</Badge>
2025-09-30 00:09:11 +02:00
</div>
2025-10-04 19:25:28 +02:00
2025-10-04 20:06:47 +02:00
{/* Second row: Details - Responsive layout */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
<div>
<div className="text-muted-foreground text-xs">IP Address</div>
<div className="font-medium text-foreground font-mono text-sm truncate">
{interface_.addresses.length > 0 ? interface_.addresses[0].ip : "N/A"}
</div>
2025-10-04 19:25:28 +02:00
</div>
2025-10-04 20:06:47 +02:00
<div>
<div className="text-muted-foreground text-xs">Speed</div>
<div className="font-medium text-foreground flex items-center gap-1">
<Zap className="h-3 w-3" />
{formatSpeed(interface_.speed)}
</div>
2025-10-04 19:45:37 +02:00
</div>
2025-10-04 20:06:47 +02:00
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs">
<span className="text-green-500"> {formatBytes(interface_.bytes_recv)}</span>
{" / "}
<span className="text-blue-500"> {formatBytes(interface_.bytes_sent)}</span>
</div>
</div>
{interface_.mac_address && (
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate">
{interface_.mac_address}
</div>
</div>
)}
2025-10-04 19:58:12 +02:00
</div>
2025-10-04 20:06:47 +02:00
</div>
)
})}
</div>
</CardContent>
</Card>
)}
2025-10-04 19:45:37 +02:00
2025-10-04 20:06:47 +02:00
{networkData.bridge_interfaces && networkData.bridge_interfaces.length > 0 && (
<Card className="bg-card border-border">
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Network className="h-5 w-5 mr-2" />
Bridge Interfaces
<Badge variant="outline" className="ml-3 bg-green-500/10 text-green-500 border-green-500/20">
{networkData.bridge_active_count ?? 0} / {networkData.bridge_total_count ?? 0} Active
</Badge>
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
{networkData.bridge_interfaces.map((interface_, index) => {
const typeBadge = getInterfaceTypeBadge(interface_.type)
return (
<div
key={index}
className="flex flex-col gap-3 p-4 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer"
onClick={() => setSelectedInterface(interface_)}
>
{/* First row: Icon, Name, Type Badge, Status */}
<div className="flex items-center gap-3 flex-wrap">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="flex items-center gap-2 min-w-0">
<div className="font-medium text-foreground">{interface_.name}</div>
<Badge variant="outline" className={typeBadge.color}>
{typeBadge.label}
</Badge>
2025-10-04 19:45:37 +02:00
</div>
2025-10-04 20:06:47 +02:00
<Badge
variant="outline"
className={
interface_.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20 ml-auto"
: "bg-red-500/10 text-red-500 border-red-500/20 ml-auto"
}
>
{interface_.status.toUpperCase()}
</Badge>
2025-10-04 19:58:12 +02:00
</div>
2025-10-04 19:45:37 +02:00
2025-10-04 20:06:47 +02:00
{/* Second row: Details - Responsive layout */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
<div>
<div className="text-muted-foreground text-xs">IP Address</div>
<div className="font-medium text-foreground font-mono text-sm truncate">
{interface_.addresses.length > 0 ? interface_.addresses[0].ip : "N/A"}
</div>
</div>
<div>
<div className="text-muted-foreground text-xs">Speed</div>
<div className="font-medium text-foreground flex items-center gap-1">
<Zap className="h-3 w-3" />
{formatSpeed(interface_.speed)}
</div>
</div>
2025-10-04 19:25:28 +02:00
<div className="col-span-2 md:col-span-1">
2025-10-04 20:06:47 +02:00
<div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs">
<span className="text-green-500"> {formatBytes(interface_.bytes_recv)}</span>
{" / "}
<span className="text-blue-500"> {formatBytes(interface_.bytes_sent)}</span>
2025-10-04 19:05:39 +02:00
</div>
</div>
2025-10-04 20:06:47 +02:00
{interface_.mac_address && (
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate">
{interface_.mac_address}
</div>
</div>
)}
</div>
2025-10-04 19:25:28 +02:00
</div>
2025-10-04 20:06:47 +02:00
)
})}
</div>
</CardContent>
</Card>
)}
2025-10-04 19:25:28 +02:00
2025-10-04 19:58:12 +02:00
{networkData.vm_lxc_interfaces && networkData.vm_lxc_interfaces.length > 0 && (
2025-10-04 19:25:28 +02:00
<Card className="bg-card border-border">
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Network className="h-5 w-5 mr-2" />
VM & LXC Network Interfaces
<Badge variant="outline" className="ml-3 bg-orange-500/10 text-orange-500 border-orange-500/20">
2025-10-04 19:58:12 +02:00
{networkData.vm_lxc_active_count ?? 0} / {networkData.vm_lxc_total_count ?? 0} Active
2025-10-04 19:25:28 +02:00
</Badge>
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
2025-10-04 19:58:12 +02:00
{networkData.vm_lxc_interfaces.map((interface_, index) => {
const vmTypeBadge = getVMTypeBadge(interface_.vm_type)
2025-10-04 19:25:28 +02:00
return (
<div
key={index}
className="flex flex-col gap-3 p-4 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer"
2025-10-04 19:58:12 +02:00
onClick={() => setSelectedInterface(interface_)}
2025-10-04 19:25:28 +02:00
>
2025-10-04 19:58:12 +02:00
{/* First row: Icon, Name, VM/LXC Badge, VM Name, Status */}
2025-10-04 19:25:28 +02:00
<div className="flex items-center gap-3 flex-wrap">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="flex items-center gap-2 min-w-0 flex-1">
2025-10-04 19:58:12 +02:00
<div className="font-medium text-foreground">{interface_.name}</div>
2025-10-04 19:25:28 +02:00
<Badge variant="outline" className={vmTypeBadge.color}>
{vmTypeBadge.label}
</Badge>
2025-10-04 19:58:12 +02:00
{interface_.vm_name && (
<div className="text-sm text-muted-foreground truncate"> {interface_.vm_name}</div>
2025-10-04 19:25:28 +02:00
)}
</div>
<Badge
variant="outline"
className={
2025-10-04 19:58:12 +02:00
interface_.status === "up"
2025-10-04 19:25:28 +02:00
? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-red-500/10 text-red-500 border-red-500/20"
}
>
2025-10-04 19:58:12 +02:00
{interface_.status.toUpperCase()}
2025-10-04 19:25:28 +02:00
</Badge>
</div>
2025-10-04 19:05:39 +02:00
2025-10-04 19:58:12 +02:00
{/* Second row: Details - Responsive layout */}
2025-10-04 19:25:28 +02:00
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
2025-10-04 19:05:39 +02:00
<div>
2025-10-04 19:25:28 +02:00
<div className="text-muted-foreground text-xs">VMID</div>
2025-10-04 19:58:12 +02:00
<div className="font-medium text-foreground">{interface_.vmid ?? "N/A"}</div>
2025-10-04 19:25:28 +02:00
</div>
<div>
<div className="text-muted-foreground text-xs">Speed</div>
2025-10-04 19:05:39 +02:00
<div className="font-medium text-foreground flex items-center gap-1">
<Zap className="h-3 w-3" />
2025-10-04 19:58:12 +02:00
{formatSpeed(interface_.speed)}
2025-10-04 19:05:39 +02:00
</div>
</div>
2025-10-04 19:25:28 +02:00
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs">
2025-10-04 19:58:12 +02:00
<span className="text-green-500"> {formatBytes(interface_.bytes_recv)}</span>
2025-10-04 19:05:39 +02:00
{" / "}
2025-10-04 19:58:12 +02:00
<span className="text-blue-500"> {formatBytes(interface_.bytes_sent)}</span>
2025-10-04 19:05:39 +02:00
</div>
</div>
2025-10-04 19:58:12 +02:00
{interface_.mac_address && (
2025-10-04 19:25:28 +02:00
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate">
2025-10-04 19:58:12 +02:00
{interface_.mac_address}
2025-10-04 19:25:28 +02:00
</div>
2025-10-04 19:05:39 +02:00
</div>
)}
2025-09-28 23:09:31 +02:00
</div>
</div>
2025-10-04 19:25:28 +02:00
)
})}
</div>
</CardContent>
</Card>
)}
2025-10-04 19:05:39 +02:00
2025-10-04 19:58:12 +02:00
{/* Interface Details Modal */}
2025-10-04 19:05:39 +02:00
<Dialog open={!!selectedInterface} onOpenChange={() => setSelectedInterface(null)}>
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Router className="h-5 w-5" />
{selectedInterface?.name} - Interface Details
</DialogTitle>
</DialogHeader>
{selectedInterface && (
<div className="space-y-6">
{/* Basic Information */}
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3">Basic Information</h3>
<div className="grid grid-cols-2 gap-4">
<div>
<div className="text-sm text-muted-foreground">Interface Name</div>
<div className="font-medium">{selectedInterface.name}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Type</div>
<Badge variant="outline" className={getInterfaceTypeBadge(selectedInterface.type).color}>
{getInterfaceTypeBadge(selectedInterface.type).label}
</Badge>
</div>
<div>
<div className="text-sm text-muted-foreground">Status</div>
<Badge
variant="outline"
className={
selectedInterface.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-red-500/10 text-red-500 border-red-500/20"
}
>
{selectedInterface.status.toUpperCase()}
</Badge>
</div>
<div>
<div className="text-sm text-muted-foreground">Speed</div>
<div className="font-medium">{formatSpeed(selectedInterface.speed)}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Duplex</div>
<div className="font-medium capitalize">{selectedInterface.duplex}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">MTU</div>
<div className="font-medium">{selectedInterface.mtu}</div>
</div>
{selectedInterface.mac_address && (
<div className="col-span-2">
<div className="text-sm text-muted-foreground">MAC Address</div>
<div className="font-medium font-mono">{selectedInterface.mac_address}</div>
</div>
)}
</div>
</div>
{/* IP Addresses */}
{selectedInterface.addresses.length > 0 && (
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3">IP Addresses</h3>
<div className="space-y-2">
{selectedInterface.addresses.map((addr, idx) => (
<div key={idx} className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
<div>
<div className="font-medium font-mono">{addr.ip}</div>
<div className="text-sm text-muted-foreground">Netmask: {addr.netmask}</div>
</div>
</div>
))}
</div>
</div>
)}
{/* Traffic Statistics */}
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3">Traffic Statistics</h3>
<div className="grid grid-cols-2 gap-4">
<div>
<div className="text-sm text-muted-foreground">Bytes Received</div>
<div className="font-medium text-green-500">{formatBytes(selectedInterface.bytes_recv)}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Bytes Sent</div>
<div className="font-medium text-blue-500">{formatBytes(selectedInterface.bytes_sent)}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Packets Received</div>
<div className="font-medium">{selectedInterface.packets_recv?.toLocaleString() || "N/A"}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Packets Sent</div>
<div className="font-medium">{selectedInterface.packets_sent?.toLocaleString() || "N/A"}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Errors In</div>
<div className="font-medium text-red-500">{selectedInterface.errors_in || 0}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Errors Out</div>
<div className="font-medium text-red-500">{selectedInterface.errors_out || 0}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Drops In</div>
<div className="font-medium text-yellow-500">{selectedInterface.drops_in || 0}</div>
</div>
<div>
<div className="text-sm text-muted-foreground">Drops Out</div>
<div className="font-medium text-yellow-500">{selectedInterface.drops_out || 0}</div>
</div>
2025-10-04 19:25:28 +02:00
{selectedInterface.packet_loss_in !== undefined && (
<div>
<div className="text-sm text-muted-foreground">Packet Loss In</div>
<div
className={`font-medium ${selectedInterface.packet_loss_in > 1 ? "text-red-500" : "text-green-500"}`}
>
{selectedInterface.packet_loss_in}%
</div>
</div>
)}
{selectedInterface.packet_loss_out !== undefined && (
<div>
<div className="text-sm text-muted-foreground">Packet Loss Out</div>
<div
className={`font-medium ${selectedInterface.packet_loss_out > 1 ? "text-red-500" : "text-green-500"}`}
>
{selectedInterface.packet_loss_out}%
</div>
</div>
)}
2025-10-04 19:05:39 +02:00
</div>
</div>
{/* Bond Information */}
{selectedInterface.type === "bond" && selectedInterface.bond_slaves && (
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3">Bond Configuration</h3>
<div className="space-y-3">
<div>
<div className="text-sm text-muted-foreground">Bonding Mode</div>
<div className="font-medium">{selectedInterface.bond_mode || "Unknown"}</div>
</div>
{selectedInterface.bond_active_slave && (
<div>
<div className="text-sm text-muted-foreground">Active Slave</div>
<div className="font-medium">{selectedInterface.bond_active_slave}</div>
</div>
)}
<div>
<div className="text-sm text-muted-foreground mb-2">Slave Interfaces</div>
<div className="flex flex-wrap gap-2">
{selectedInterface.bond_slaves.map((slave, idx) => (
<Badge
key={idx}
variant="outline"
className="bg-purple-500/10 text-purple-500 border-purple-500/20"
>
{slave}
</Badge>
))}
</div>
</div>
</div>
</div>
)}
{/* Bridge Information */}
{selectedInterface.type === "bridge" && selectedInterface.bridge_members && (
<div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3">Bridge Configuration</h3>
<div>
<div className="text-sm text-muted-foreground mb-2">Member Interfaces</div>
<div className="flex flex-wrap gap-2">
{selectedInterface.bridge_members.length > 0 ? (
selectedInterface.bridge_members.map((member, idx) => (
<Badge
key={idx}
variant="outline"
className="bg-green-500/10 text-green-500 border-green-500/20"
>
{member}
</Badge>
))
) : (
<div className="text-sm text-muted-foreground">No members</div>
)}
</div>
</div>
</div>
)}
</div>
)}
</DialogContent>
</Dialog>
2025-09-28 23:09:31 +02:00
</div>
)
}