import { formatUptime, getUptimeColor } from '../hooks/useMonitor'; // 统计概览卡片 export default function StatsCard({ websites }) { // 计算统计数据 const stats = { total: websites?.length || 0, online: 0, offline: 0, avgUptime24h: 0, avgUptime7d: 0, avgLatency: 0, }; if (websites && websites.length > 0) { let totalUptime24h = 0; let totalUptime7d = 0; let totalLatency = 0; let latencyCount = 0; websites.forEach(site => { // 检查所有URL的状态 const hasOnlineUrl = site.url_statuses?.some(us => us.current_state?.is_up); if (hasOnlineUrl) { stats.online++; } else { stats.offline++; } totalUptime24h += site.uptime_24h || 0; totalUptime7d += site.uptime_7d || 0; site.url_statuses?.forEach(us => { if (us.current_state?.latency) { totalLatency += us.current_state.latency; latencyCount++; } }); }); stats.avgUptime24h = totalUptime24h / stats.total; stats.avgUptime7d = totalUptime7d / stats.total; stats.avgLatency = latencyCount > 0 ? Math.round(totalLatency / latencyCount) : 0; } return (
监控网站
{stats.total}
24h 可用率
{formatUptime(stats.avgUptime24h)}
7d 可用率
{formatUptime(stats.avgUptime7d)}
平均延迟
{stats.avgLatency} ms