import React, { Suspense, useMemo } from 'react'; import { Card, CardContent, Typography, Box, Tooltip as MuiTooltip, } from '@mui/material'; import { motion } from 'framer-motion'; import { AlertTriangle, CheckCircle, AlertCircle } from 'lucide-react'; import { LazyPieChart, Pie, Cell, ResponsiveContainer, ChartLoadingFallback } from '../../utils/lazyRecharts'; import { SystemHealth } from '../../types/monitoring'; interface ErrorRateGaugeProps { systemHealth: SystemHealth | null; terminalTheme?: boolean; terminalColors?: any; } /** * ErrorRateGauge - Semi-circular gauge showing API error rate * * Visual gauge with: * - Green (0-5%): Healthy * - Yellow (5-10%): Warning * - Red (>10%): Critical */ const ErrorRateGauge: React.FC = ({ systemHealth, terminalTheme = false, terminalColors }) => { const errorRate = systemHealth?.error_rate || 0; const recentRequests = systemHealth?.recent_requests || 0; const recentErrors = systemHealth?.recent_errors || 0; // Determine status and color const { status, color, icon } = useMemo(() => { if (errorRate <= 5) { return { status: 'Healthy', color: terminalTheme ? (terminalColors?.success || '#22c55e') : '#22c55e', icon: }; } else if (errorRate <= 10) { return { status: 'Warning', color: terminalTheme ? (terminalColors?.warning || '#f59e0b') : '#f59e0b', icon: }; } else { return { status: 'Critical', color: terminalTheme ? (terminalColors?.error || '#ef4444') : '#ef4444', icon: }; } }, [errorRate, terminalTheme, terminalColors]); // Data for semi-circular gauge (using Pie chart) const gaugeData = [ { name: 'Errors', value: errorRate, fill: color }, { name: 'Success', value: Math.max(0, 100 - errorRate), fill: 'rgba(255,255,255,0.1)' } ]; return ( {icon} Error Rate Gauge }> {/* Center value display */} {errorRate.toFixed(1)}% Error Rate {/* Stats */} {recentRequests.toLocaleString()} Requests {recentErrors.toLocaleString()} Errors {status} Status ); }; export default ErrorRateGauge;