"use client" import { useState, useEffect } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Alert, AlertDescription } from "@/components/ui/alert" import { RefreshCw, Database, Activity, AlertTriangle, CheckCircle } from "lucide-react" interface PoolStats { totalConnections: number freeConnections: number acquiringConnections: number connectionLimit: number } interface HealthData { status: string responseTime?: number poolStats?: PoolStats recommendations?: string[] error?: string timestamp: string } export function DatabaseMonitor() { const [healthData, setHealthData] = useState(null) const [loading, setLoading] = useState(false) const [autoRefresh, setAutoRefresh] = useState(false) const fetchHealth = async () => { setLoading(true) try { const response = await fetch("/api/admin/db-health") const data = await response.json() setHealthData(data) } catch (error) { console.error("Error fetching database health:", error) setHealthData({ status: "error", error: "Failed to fetch health data", timestamp: new Date().toISOString(), }) } finally { setLoading(false) } } useEffect(() => { fetchHealth() }, []) useEffect(() => { let interval: NodeJS.Timeout if (autoRefresh) { interval = setInterval(fetchHealth, 5000) // Refresh every 5 seconds } return () => { if (interval) clearInterval(interval) } }, [autoRefresh]) const getStatusIcon = (status: string) => { switch (status) { case "healthy": return case "unhealthy": return default: return } } const getUtilizationColor = (utilization: number) => { if (utilization > 0.8) return "text-red-600" if (utilization > 0.6) return "text-yellow-600" return "text-green-600" } return (
מוניטור מסד נתונים
{healthData ? ( <> {/* Status Overview */}
{getStatusIcon(healthData.status)} סטטוס: {healthData.status === "healthy" ? "תקין" : "לא תקין"} {healthData.responseTime && ( ({healthData.responseTime}ms) )}
{/* Pool Statistics */} {healthData.poolStats && (
{healthData.poolStats.totalConnections}
חיבורים פעילים
{healthData.poolStats.freeConnections}
חיבורים זמינים
{healthData.poolStats.acquiringConnections}
ממתינים לחיבור
{healthData.poolStats.connectionLimit}
מגבלת חיבורים
)} {/* Utilization Bar */} {healthData.poolStats && (
ניצולת Pool {Math.round( ((healthData.poolStats.totalConnections - healthData.poolStats.freeConnections) / healthData.poolStats.connectionLimit) * 100, )} %
)} {/* Recommendations */} {healthData.recommendations && healthData.recommendations.length > 0 && (
המלצות:
    {healthData.recommendations.map((rec, index) => (
  • {rec}
  • ))}
)} {/* Error Display */} {healthData.error && ( {healthData.error} )} {/* Timestamp */}
עודכן: {new Date(healthData.timestamp).toLocaleString("he-IL")}
) : (
טוען נתוני בריאות מסד הנתונים...
)}
) }