"use client" import { useState, useEffect } from 'react' import SpeedometerGauge from './SpeedometerGauge' interface TelemetryData { cpu: number memory: number disk: number gpuMemoryUsed?: number gpuMemoryTotal?: number gpuTemperature?: number } interface Sandbox { id: string name: string ip: string status: string } export default function TelemetryDisplay() { const [selectedSandbox, setSelectedSandbox] = useState(null) const [telemetry, setTelemetry] = useState({ cpu: 0, memory: 0, disk: 0, gpuMemoryUsed: 0, gpuMemoryTotal: 0, gpuTemperature: 0 }) const [sandboxes, setSandboxes] = useState([]) const [loading, setLoading] = useState(true) // Fetch sandboxes useEffect(() => { fetchSandboxes() }, []) // Fetch telemetry when sandbox changes useEffect(() => { if (selectedSandbox) { fetchTelemetry(selectedSandbox) } else { fetchCombinedTelemetry() } }, [selectedSandbox]) const fetchSandboxes = async () => { try { const response = await fetch('/api/telemetry/real') const data = await response.json() // Filter sandboxes from pod data const sandboxList = (data.pods?.items || []).map((pod: any, index: number) => ({ id: pod.metadata?.name || `sandbox-${index}`, name: pod.metadata?.name || `Sandbox ${index + 1}`, ip: pod.status?.podIP || `10.42.0.${index + 1}`, status: pod.status?.phase || 'Unknown' })) setSandboxes(sandboxList) } catch (error) { console.error('Error fetching sandboxes:', error) } finally { setLoading(false) } } const fetchTelemetry = async (sandboxId: string) => { try { const response = await fetch(`/api/telemetry/sandbox/${sandboxId}`) const data = await response.json() setTelemetry(data) } catch (error) { console.error('Error fetching telemetry:', error) } } const fetchCombinedTelemetry = async () => { try { const response = await fetch('/api/telemetry/combined') const data = await response.json() setTelemetry(data) } catch (error) { console.error('Error fetching telemetry:', error) } } const handleSandboxClick = (sandboxId: string) => { setSelectedSandbox(selectedSandbox === sandboxId ? null : sandboxId) } if (loading) { return
Loading telemetry...
} return (
{/* Sandbox Selection */} {sandboxes.length > 0 && (

Select Sandbox

{sandboxes.map((sandbox) => ( ))}
)} {/* Telemetry Gauges */}
{telemetry.gpuMemoryUsed !== undefined && telemetry.gpuMemoryTotal && ( )}
{/* Additional Metrics */} {telemetry.gpuTemperature && (

GPU Metrics

Temperature

{telemetry.gpuTemperature.toFixed(1)}°C

Memory Used

{telemetry.gpuMemoryUsed.toFixed(1)} / {telemetry.gpuMemoryTotal.toFixed(1)} GB

)} {/* Selected Sandbox Info */} {selectedSandbox && (

Selected Sandbox

IP: {sandboxes.find(s => s.id === selectedSandbox)?.ip}

Status: {sandboxes.find(s => s.id === selectedSandbox)?.status}

)}
) }