"use client"; import { DashboardLayout } from "@/components/dashboard/DashboardLayout"; import { Progress } from "@/components/ui/progress"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { type ChartConfig } from "@/components/ui/chart"; import GradientAreaChart from "@/components/GradientAreaChart"; import { getMetrics } from "@/core/client/metrics"; import { useEffect, useState } from "react"; import { useIsMobile } from "@/hooks/use-mobile"; import RadialChart from "@/components/RadialChart"; import { Node, NodeLiveData } from "@/lib/types"; import { getLiveNodes } from "@/core/client/node"; import { average } from "@/lib/format"; const containerMetrics = [ { name: "api-gateway-1", cpu: 45, memory: 62, network: "12.4 MB/s" }, { name: "api-gateway-2", cpu: 52, memory: 58, network: "10.2 MB/s" }, { name: "api-gateway-3", cpu: 38, memory: 55, network: "8.8 MB/s" }, { name: "auth-service-1", cpu: 28, memory: 45, network: "3.2 MB/s" }, { name: "auth-service-2", cpu: 32, memory: 48, network: "2.8 MB/s" }, { name: "postgres-db-1", cpu: 65, memory: 78, network: "8.1 MB/s" }, { name: "redis-cache-1", cpu: 12, memory: 34, network: "1.8 MB/s" }, { name: "worker-queue-1", cpu: 55, memory: 48, network: "5.6 MB/s" }, ]; const cpuChartConfig = { cpu: { label: "CPU Usage", color: "var(--chart-1)" }, } satisfies ChartConfig; const memoryChartConfig = { memory: { label: "RAM Usage", color: "var(--chart-3)" }, } satisfies ChartConfig; const networkChartConfig = { in: { label: "Inbound", color: "var(--chart-2)" }, out: { label: "Outbound", color: "var(--chart-4)" }, } satisfies ChartConfig; export default function MonitoringPage() { const [data, setData] = useState< { time: string; cpu: number; memory: number; in: number; out: number; }[] >([]); const isMobile = useIsMobile(); const [liveData, setLiveData] = useState<{ cpuUsage: number; ramUsage: number; }>(); useEffect(() => { const fetchNodes = async () => { const nodes = await getLiveNodes(); setLiveData({ cpuUsage: average(nodes, (n) => n.liveData.cpu.usage), ramUsage: average(nodes, (n) => n.liveData.memory.usage), }); }; fetchNodes(); const interval = setInterval(fetchNodes, 3000); return () => clearInterval(interval); }, []); useEffect(() => { async function fetchMetrics() { setData(await getMetrics()); } fetchMetrics(); const i = setInterval(fetchMetrics, 30000); return () => clearInterval(i); }, []); return ( {/* Summary Stats */} {isMobile ? (
CPU RAM
) : (
CPU usage
{liveData?.cpuUsage?.toFixed(0) || 0}%
Memory usage
{liveData?.ramUsage?.toFixed(0) || 0}%
Network In
38 MB/s
↑ 12% from avg
Network Out
28 MB/s
↓ 5% from avg
)} {/* CPU & Memory Charts */}
{/* Network Metrics */}
{/* Container Metrics */} Container Metrics
{containerMetrics.map((container) => (
{container.name}
CPU {container.cpu}%
Memory {container.memory}%
Network {container.network}
))}
); }