"use client"; import { useEffect, useState } from "react"; import { fetchClient } from "@/lib/api-client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; interface Status { uptimeSeconds: number; memory: Record; versions: Record; counts: { vendors: number; orders: number; products: number; chats: number }; } function formatDuration(seconds: number) { const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); const s = seconds % 60; return `${h}h ${m}m ${s}s`; } function formatBytes(bytes: number): string { if (bytes === 0) return '0 Bytes'; if (bytes < 0) return '0 Bytes'; // Handle negative values const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k))); // Ensure i is at least 0 // Clamp i to valid array index const clampedI = Math.min(i, sizes.length - 1); return Math.round(bytes / Math.pow(k, clampedI) * 100) / 100 + ' ' + sizes[clampedI]; } export default function SystemStatusCard() { const [data, setData] = useState(null); const [error, setError] = useState(null); const [showDebug, setShowDebug] = useState(false); useEffect(() => { let mounted = true; (async () => { try { const res = await fetchClient("/admin/system-status"); if (mounted) setData(res); } catch (e: any) { if (mounted) setError(e?.message || "Failed to load status"); } })(); return () => { mounted = false; }; }, []); return (

System status

Uptime, versions, environment

OK
{error &&

{error}

} {data && (
Uptime
{formatDuration(data.uptimeSeconds)}
Node
{data.versions?.node}
Vendors
{data.counts?.vendors}
Orders
{data.counts?.orders}
)}
{showDebug && data && ( Debug: Raw System Status Data Complete system status response from backend
Memory Usage:
RSS (Resident Set Size): {formatBytes(data.memory?.rss || 0)}
Heap Total: {formatBytes(data.memory?.heapTotal || 0)}
Heap Used: {formatBytes(data.memory?.heapUsed || 0)}
External: {formatBytes(data.memory?.external || 0)}
Array Buffers: {formatBytes(data.memory?.arrayBuffers || 0)}
Versions:
{Object.entries(data.versions || {}).map(([key, value]) => (
{key}: {value}
))}
Counts:
Vendors: {data.counts?.vendors || 0}
Orders: {data.counts?.orders || 0}
Products: {data.counts?.products || 0}
Chats: {data.counts?.chats || 0}
Uptime:
{data.uptimeSeconds} seconds ({formatDuration(data.uptimeSeconds)})
Full JSON Response
                  {JSON.stringify(data, null, 2)}
                
)}
); }