'use client'; import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { RefreshCw, TrendingUp, Cpu, HardDrive, Activity } from 'lucide-react'; import { api } from '@/lib/api'; import { MetricsChart } from '@/components/metrics/MetricsChart'; const METRIC_PRESETS = [ { name: 'CPU Usage', metric: 'cpu.usage_percent', service: 'system', icon: Cpu }, { name: 'Memory Usage', metric: 'memory.used_percent', service: 'system', icon: Activity }, { name: 'Load Average', metric: 'cpu.load_avg_1', service: 'system', icon: TrendingUp }, { name: 'Disk Usage', metric: 'disk.used_percent', service: 'system', icon: HardDrive }, { name: 'Network Sent', metric: 'network.bytes_sent', service: 'system', icon: TrendingUp }, { name: 'Network Recv', metric: 'network.bytes_recv', service: 'system', icon: TrendingUp }, { name: 'Containers Running', metric: 'containers.running', service: 'docker', icon: Activity }, { name: 'Container CPU', metric: 'container.cpu_percent', service: 'docker', icon: Cpu }, ]; export default function MetricsPage() { const [timeRange, setTimeRange] = useState('1h'); const [selectedMetrics, setSelectedMetrics] = useState([ 'cpu.usage_percent', 'memory.used_percent', ]); const getTimeFrom = () => { const ranges: Record = { '15m': 15 * 60 * 1000, '1h': 60 * 60 * 1000, '6h': 6 * 60 * 60 * 1000, '24h': 24 * 60 * 60 * 1000, }; return new Date(Date.now() - (ranges[timeRange] || ranges['1h'])).toISOString(); }; const toggleMetric = (metric: string) => { setSelectedMetrics((prev) => prev.includes(metric) ? prev.filter((m) => m !== metric) : [...prev, metric] ); }; return (

Metrics

{/* Metric Selector */}
{METRIC_PRESETS.map((preset) => { const Icon = preset.icon; const isSelected = selectedMetrics.includes(preset.metric); return ( ); })}
{/* Charts Grid */}
{selectedMetrics.map((metric) => { const preset = METRIC_PRESETS.find((p) => p.metric === metric); return ( ); })}
{selectedMetrics.length === 0 && (
Select metrics to display
)}
); }