"use client"; import { useEffect, useState } from "react"; import { AdminLayout } from "@/components/layout/admin-layout"; import { PageHeader } from "@/components/layout/page-header"; import { Card } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; import { ErrorBanner } from "@/components/ui/error-banner"; import { SecondaryButton } from "@/components/ui/primary-button"; import { METRICS_THRESHOLDS } from "@/lib/frontend/constants"; import { adminGetMetrics } from "@/lib/frontend/api-client"; import { useAuth } from "@/hooks/use-auth"; import type { DataPageStatus, MetricsDashboard } from "@/lib/frontend/types"; function MetricCard({ label, value, suffix, threshold, higherIsBetter = true, }: { label: string; value: number; suffix?: string; threshold?: number; higherIsBetter?: boolean; }) { const below = threshold !== undefined && (higherIsBetter ? value < threshold : value > threshold); return ( {label} {value} {suffix} ); } export default function MetricsDashboardPage() { const { token } = useAuth(); const [status, setStatus] = useState("loading"); const [metrics, setMetrics] = useState(null); const load = async () => { if (!token) return; setStatus("loading"); const res = await adminGetMetrics("", token); if (res.code !== 0) { setStatus("error"); return; } setMetrics(res.data); setStatus("success"); }; useEffect(() => { void load(); }, [token]); return ( {status === "loading" && ( {Array.from({ length: 4 }).map((_, i) => ( ))} )} {status === "error" && ( void load()}>重试} > 加载指标失败 )} {status === "success" && metrics && ( P95 延迟 {metrics.p95_latency_ms} ms 队列深度 {metrics.queue_depth} 未处理预警 0 ? "text-warning" : "" }`} > {metrics.open_alerts_count} )} ); }
{label}
{value} {suffix}
P95 延迟
{metrics.p95_latency_ms} ms
队列深度
{metrics.queue_depth}
未处理预警
0 ? "text-warning" : "" }`} > {metrics.open_alerts_count}