import { useQuery, useQueryClient } from '@tanstack/react-query' import { Table, Card, Row, Col, Statistic, Button, Typography, Tabs } from 'antd' import { ReloadOutlined, DashboardOutlined, CloudOutlined, NodeIndexOutlined } from '@ant-design/icons' import { metricsAPI } from '@/api' import dayjs from 'dayjs' const { Title } = Typography function MetricsPage() { const qc = useQueryClient() const { data: overview } = useQuery({ queryKey: ['metrics', 'overview'], queryFn: () => metricsAPI.overview(), staleTime: 10_000 }) const { data: top } = useQuery({ queryKey: ['metrics', 'top'], queryFn: () => metricsAPI.top(), staleTime: 10_000 }) const { data: recent } = useQuery({ queryKey: ['metrics', 'recent'], queryFn: () => metricsAPI.recent(), staleTime: 5_000 }) const { data: ai } = useQuery({ queryKey: ['metrics', 'ai'], queryFn: () => metricsAPI.ai(), staleTime: 10_000 }) const { data: worker } = useQuery({ queryKey: ['metrics', 'worker'], queryFn: () => metricsAPI.worker(), staleTime: 10_000 }) const topCols = [ { title: '接口', dataIndex: 'path', width: 300, ellipsis: true }, { title: '方法', dataIndex: 'method', width: 70 }, { title: '调用', dataIndex: 'calls', width: 70, align: 'center' as const }, { title: '平均耗时', dataIndex: 'avgDuration', width: 100, align: 'center' as const, render: (v: number) => 1000 ? '#ff4d4f' : v > 500 ? '#faad14' : '#52c41a' }}>{v}ms }, ] const recentCols = [ { title: '时间', dataIndex: 'createdAt', width: 140, render: (d: string) => dayjs(d).format('HH:mm:ss') }, { title: '接口', dataIndex: 'path', ellipsis: true }, { title: '方法', dataIndex: 'method', width: 60 }, { title: '状态', dataIndex: 'statusCode', width: 60, render: (v: number) => = 400 ? '#ff4d4f' : '#52c41a' }}>{v} }, { title: '耗时', dataIndex: 'duration', width: 70, align: 'center' as const, render: (v: number) => `${v}ms` }, ] const aiProviderCols = [ { title: 'Provider', dataIndex: 'name', width: 120 }, { title: '调用量', dataIndex: 'calls', width: 80, align: 'center' as const }, { title: '平均耗时', dataIndex: 'avgLatencyMs', width: 100, align: 'center' as const, render: (v: number) => 5000 ? '#ff4d4f' : v > 2000 ? '#faad14' : '#52c41a' }}>{v}ms }, { title: '失败率', dataIndex: 'failureRate', width: 80, align: 'center' as const }, { title: '成本', dataIndex: 'totalCost', width: 80, align: 'center' as const, render: (v: string) => `$${v}` }, ] const workerCols = [ { title: '队列', dataIndex: 'name', width: 160 }, { title: '总任务', dataIndex: 'total', width: 80, align: 'center' as const }, { title: '完成', dataIndex: 'completed', width: 80, align: 'center' as const }, { title: '失败', dataIndex: 'failed', width: 80, align: 'center' as const, render: (v: number) => v > 0 ? {v} : 0 }, { title: '成功率', dataIndex: 'successRate', width: 80, align: 'center' as const }, ] return (