import React from 'react'; import { Card, CardContent, Typography, Box, Chip, IconButton, Tooltip, LinearProgress, } from '@mui/material'; import { motion } from 'framer-motion'; import { Activity, RefreshCw, AlertTriangle, CheckCircle, XCircle, Clock, Zap } from 'lucide-react'; // Types import { SystemHealth } from '../../types/monitoring'; // Utils import { getHealthStatusColor, getHealthStatusIcon, formatResponseTime, formatErrorRate, getPerformanceStatus } from '../../services/monitoringService'; interface SystemHealthIndicatorProps { systemHealth: SystemHealth | null; onRefresh: () => void; } const SystemHealthIndicator: React.FC = ({ systemHealth, onRefresh }) => { if (!systemHealth) { return ( Loading system health... ); } const performanceStatus = getPerformanceStatus(0, systemHealth.error_rate); const healthColor = getHealthStatusColor(systemHealth.status); const healthIcon = getHealthStatusIcon(systemHealth.status); const getStatusChip = () => { let chipColor: 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' = 'default'; if (systemHealth.status === 'healthy') chipColor = 'success'; else if (systemHealth.status === 'warning') chipColor = 'warning'; else if (systemHealth.status === 'critical') chipColor = 'error'; return ( {healthIcon}} label={systemHealth.status.charAt(0).toUpperCase() + systemHealth.status.slice(1)} color={chipColor} size="small" sx={{ fontWeight: 'bold' }} /> ); }; return ( {/* Header */} System Health {/* Status Chip */} {getStatusChip()} {/* Main Health Indicator */} {healthIcon} {/* Pulse animation for critical status */} {systemHealth.status === 'critical' && ( )} {systemHealth.status.charAt(0).toUpperCase() + systemHealth.status.slice(1)} System Status {/* Metrics */} Recent Requests {systemHealth.recent_requests.toLocaleString()} Recent Errors 0 ? '#ff6b6b' : '#ffffff' }} > {systemHealth.recent_errors} Error Rate 5 ? '#ff6b6b' : '#ffffff' }} > {formatErrorRate(systemHealth.error_rate)} {/* Error Rate Progress */} Error Rate {formatErrorRate(systemHealth.error_rate)} 10 ? '#ef4444' : systemHealth.error_rate > 5 ? '#f59e0b' : '#22c55e', borderRadius: 4, } }} /> {systemHealth.error_rate > 10 ? 'High error rate detected' : systemHealth.error_rate > 5 ? 'Moderate error rate' : 'Normal error rate'} {/* Performance Indicators */} Performance Status {performanceStatus.icon} {performanceStatus.status.charAt(0).toUpperCase() + performanceStatus.status.slice(1)} Last updated: {new Date(systemHealth.timestamp).toLocaleTimeString()} {/* Quick Actions */} Logs Metrics {/* Decorative Elements */} ); }; export default SystemHealthIndicator;