// SNMP 概览图表 — 设备状态分布 + CPU 对比 // Logan.Li import { useMemo } from 'react'; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Cell, PieChart, Pie, } from 'recharts'; import { Card, CardContent } from '@/components/ui/card'; import { BarChart3, PieChart as PieChartIcon } from 'lucide-react'; import type { SnmpDevice, SnmpOverviewItem } from './helpers'; import { fmtMetricValue, statusColor } from './helpers'; import { MonitorChartTooltip, MONITOR_PIE_STROKE, MonitorPieTooltip } from '../shared/monitorChartTheme'; import { useTranslation } from 'react-i18next'; interface Props { devices: SnmpDevice[]; overview: SnmpOverviewItem[]; } export function SnmpOverviewCharts({ devices, overview }: Props) { const { t } = useTranslation(); const statusData = useMemo(() => { const online = devices.filter((d) => d.status === 'online').length; const error = devices.filter((d) => d.status === 'error').length; const offline = devices.length - online - error; return [ { name: t('common.online'), value: online, fill: 'var(--dg-green)' }, { name: t('common.abnormal'), value: error, fill: 'var(--dg-red)' }, { name: t('common.offline'), value: offline, fill: 'var(--dg-text-muted)' }, ].filter((d) => d.value > 0); }, [devices]); const cpuData = useMemo(() => { return overview .filter((o) => o.cpu != null && o.cpu > 0) .map((o) => ({ name: o.name.length > 10 ? `${o.name.slice(0, 10)}…` : o.name, fullName: o.name, cpu: o.cpu ?? 0, fill: statusColor(o.status), })) .sort((a, b) => b.cpu - a.cpu); }, [overview]); if (devices.length === 0) return null; return (

{t('monitor.snmpoverviewcharts.s64f5a4')}

{cpuData.length === 0 ? (

{t('monitor.snmpoverviewcharts.s1f4418')}

) : ( `${v}%`} /> fmtMetricValue(v, '%')} nameFormatter={() => 'CPU'} /> )} labelFormatter={(_, payload) => { const item = payload?.[0]?.payload as { fullName?: string } | undefined; return item?.fullName ?? ''; }} /> {cpuData.map((entry) => ( ))} )}

{t('monitor.snmpoverviewcharts.sbb0ae9')}

{statusData.map((entry) => ( ))} } />
{statusData.map((d) => (
{d.name} {d.value}
))}
); }