import React from 'react'; import TitleCard from '../components/TitleCard'; import { useModelList } from '../services/modelRegistryApi'; import { useSystemHealth } from '../services/healthApi'; import { useInferenceSummary } from '../services/auditApi'; import { FaPlay, FaDatabase, FaClock, FaCheckCircle, FaTimesCircle, FaPercent, FaSyncAlt } from 'react-icons/fa'; import { Link } from 'react-router-dom'; // ---------------------------------------------------- // Helper Component: สรุปตัวเลขสถิติ (Stats) // ---------------------------------------------------- const StatCard = ({ icon, title, value, unit, colorClass, linkPath, isLoading }) => { // แสดง loading spinner ถ้ากำลังโหลดข้อมูล const displayValue = isLoading ? ( ) : ( value ); return (
{icon}
{title}
{displayValue} {unit}
{linkPath && (
ดูรายละเอียด
)}
); }; function Dashboard() { // Hooks สำหรับดึงข้อมูลสถานะ const { data: models, isLoading: modelsLoading } = useModelList(); const { data: health, isLoading: healthLoading, isFetching: healthFetching } = useSystemHealth(); const { data: summary, isLoading: summaryLoading } = useInferenceSummary(); // --- Logic คำนวณ --- const activeModelCount = models?.filter(m => m.status === 'ACTIVE').length || 0; const totalModelCount = models?.length || 0; // Health Status const healthStatus = health?.status || (healthLoading ? 'CHECKING' : 'UNKNOWN'); const isHealthy = healthStatus === 'Healthy'; const healthIcon = isHealthy ? : ; const healthColor = isHealthy ? 'text-success' : 'text-error'; // Inference Stats (จาก useInferenceSummary) const totalRuns = summary?.total_runs || 0; const successRate = summary?.success_rate || 0; const avgLatencyMs = summary?.avg_latency_ms || 0; return (

แดชบอร์ด/ภาพรวม

{/* 1. ส่วนแสดงสถิติสำคัญ (KPI Cards) */}
{/* Card 1: Model Active Count */} } title="Model พร้อมรัน (ACTIVE)" value={activeModelCount} unit={`จาก ${totalModelCount}`} colorClass="text-success" linkPath="/dashboard/model-registry" isLoading={modelsLoading} /> {/* Card 2: Total Inference Runs (Audit Log) */} } title="งานรันทั้งหมด (24 ชม.)" value={totalRuns} unit="ครั้ง" colorClass="text-info" isLoading={summaryLoading} // Note: ต้องมีเมนู Pipeline Logs หรือ Audit Log List /> {/* Card 3: Success Rate (Audit Log) */} } title="Success Rate (24 ชม.)" value={successRate} unit="%" colorClass={successRate > 90 ? "text-success" : "text-warning"} isLoading={summaryLoading} /> {/* Card 4: Avg Latency (Audit Log) */} } title="Latency เฉลี่ย (AI)" value={avgLatencyMs} unit="ms" colorClass={avgLatencyMs > 5000 ? "text-error" : "text-warning"} isLoading={summaryLoading} />
{/* 2. ส่วนแสดงสถานะ Infrastructure (Health) */} : null} >

ตรวจสอบสถานะของ DB, Redis, MinIO, และ AI Model Endpoints ได้ที่เมนูสถานะระบบ

{/* 3. ส่วนแสดง Log ล่าสุด (Audit Log) */}
                    {summaryLoading ? "กำลังโหลด Log ล่าสุด..." : JSON.stringify(summary?.last_logs || [], null, 2)}
                
); } export default Dashboard;