feat: Add NVIDIA industrial design dashboard with Create/Destoy sandbox workflows
- Industrial dark theme with #76B900 NVIDIA green accents - Real-time telemetry from Kubernetes API - Create Sandbox button and workflow - Destroy Sandbox mode with destructive confirmation overlay - Sidebar fetches pod data directly from /api/telemetry/real - Fixed TypeError with defensive array checks - Technical typography, sharp corners, data-dense panels - Status indicators: GREEN RUNNING, red DESTROY mode
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
interface GaugeProps {
|
||||
value: number
|
||||
max: number
|
||||
unit: string
|
||||
color: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export default function CompactGauge({ value, max, unit, color, label }: GaugeProps) {
|
||||
const percentage = Math.min(100, Math.max(0, (value / max) * 100))
|
||||
|
||||
return (
|
||||
<div className="metric p-4">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider font-semibold">{label}</span>
|
||||
<span className="text-lg font-mono font-bold" style={{ color }}>
|
||||
{value.toFixed(1)}<span className="text-xs ml-0.5">{unit}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="w-full h-2 bg-[var(--metric-bg)] rounded-sm overflow-hidden border border-[var(--metric-border)]">
|
||||
<div
|
||||
className="h-full rounded-sm transition-all duration-500 ease-out"
|
||||
style={{
|
||||
width: `${percentage}%`,
|
||||
backgroundColor: color,
|
||||
transition: 'width 0.5s ease-out'
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
"use client"
|
||||
import { useState, useEffect } from 'react'
|
||||
import CompactGauge from './CompactGauge'
|
||||
|
||||
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 CompactTelemetryDisplay() {
|
||||
const [telemetry, setTelemetry] = useState<TelemetryData>({
|
||||
cpu: 0, memory: 0, disk: 0
|
||||
})
|
||||
const [sandboxes, setSandboxes] = useState<Sandbox[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [selectedSandbox, setSelectedSandbox] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetchSandboxes()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedSandbox) {
|
||||
fetchTelemetry()
|
||||
} else {
|
||||
fetchCombinedTelemetry()
|
||||
}
|
||||
}, [selectedSandbox])
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
if (selectedSandbox) {
|
||||
fetchTelemetry()
|
||||
} else {
|
||||
fetchCombinedTelemetry()
|
||||
}
|
||||
}, 5000)
|
||||
return () => clearInterval(interval)
|
||||
}, [selectedSandbox])
|
||||
|
||||
const fetchSandboxes = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/telemetry/real')
|
||||
const data = await response.json()
|
||||
const sandboxList = (data.pods?.items || []).slice(0, 5).map((pod: any, index: number) => ({
|
||||
id: pod.metadata?.name || `sandbox-${index}`,
|
||||
name: pod.metadata?.name?.substring(0, 15) || `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 () => {
|
||||
try {
|
||||
const response = await fetch('/api/telemetry/combined')
|
||||
const data = await response.json()
|
||||
setTelemetry(data)
|
||||
} catch (error) {
|
||||
console.error('Error fetching telemetry:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchCombinedTelemetry = fetchTelemetry
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-40">
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] font-mono uppercase tracking-wider">
|
||||
INITIALIZING TELEMETRY...
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Sandbox Selector - Technical */}
|
||||
{sandboxes.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 mb-4">
|
||||
<button
|
||||
onClick={() => setSelectedSandbox(null)}
|
||||
className={`px-3 py-1 rounded-sm text-xs font-mono uppercase tracking-wider transition-colors ${
|
||||
!selectedSandbox
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:bg-[var(--background-panel)]'
|
||||
}`}
|
||||
>
|
||||
ALL ({sandboxes.length})
|
||||
</button>
|
||||
{sandboxes.map((sandbox) => (
|
||||
<button
|
||||
key={sandbox.id}
|
||||
onClick={() => setSelectedSandbox(sandbox.id)}
|
||||
className={`px-3 py-1 rounded-sm text-xs font-mono uppercase tracking-wider transition-colors ${
|
||||
selectedSandbox === sandbox.id
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:bg-[var(--background-panel)]'
|
||||
}`}
|
||||
>
|
||||
{sandbox.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Main Metrics - 2x2 Grid */}
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<CompactGauge
|
||||
value={telemetry.cpu}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="CPU"
|
||||
/>
|
||||
<CompactGauge
|
||||
value={telemetry.memory}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="MEMORY"
|
||||
/>
|
||||
<CompactGauge
|
||||
value={telemetry.disk}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="DISK"
|
||||
/>
|
||||
{telemetry.gpuMemoryUsed !== undefined && telemetry.gpuMemoryTotal && (
|
||||
<CompactGauge
|
||||
value={(telemetry.gpuMemoryUsed / telemetry.gpuMemoryTotal) * 100}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#0D47A1"
|
||||
label="GPU MEM"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Secondary Metrics - Technical Panels */}
|
||||
{(telemetry.gpuTemperature || telemetry.gpuMemoryUsed) && (
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
{telemetry.gpuTemperature && (
|
||||
<div className="metric p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">GPU TEMP</span>
|
||||
<span className="text-xl font-mono text-[var(--nvidia-green)]">
|
||||
{telemetry.gpuTemperature.toFixed(1)}°C
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{telemetry.gpuMemoryUsed !== undefined && telemetry.gpuMemoryTotal && (
|
||||
<div className="metric p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">GPU USED</span>
|
||||
<span className="text-xl font-mono text-[var(--nvidia-green)]">
|
||||
{telemetry.gpuMemoryUsed.toFixed(1)} / {telemetry.gpuMemoryTotal.toFixed(1)} GB
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Status Bar - Technical */}
|
||||
<div className="flex items-center justify-between text-[10px] text-[var(--foreground-dim)] mt-4 pt-4 border-t border-[var(--border-subtle)]">
|
||||
<span className="font-mono uppercase tracking-wider">
|
||||
LAST UPDATE: {new Date(telemetry.timestamp || Date.now()).toLocaleTimeString()}
|
||||
</span>
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="w-2 h-2 bg-[var(--status-running)] animate-pulse"></span>
|
||||
<span className="font-mono uppercase">LIVE</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
"use client"
|
||||
import { useState, useEffect } from 'react'
|
||||
import CompactGauge from './CompactGauge'
|
||||
|
||||
interface TelemetryData {
|
||||
cpu: number
|
||||
memory: number
|
||||
disk: number
|
||||
gpuMemoryUsed?: number
|
||||
gpuMemoryTotal?: number
|
||||
gpuTemperature?: number
|
||||
}
|
||||
|
||||
interface SandboxConfig {
|
||||
name: string
|
||||
description: string
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
interface SandboxDetailsProps {
|
||||
sandboxId: string | null
|
||||
sandboxName: string | null
|
||||
sandboxIP: string | null
|
||||
sandboxStatus: string | null
|
||||
}
|
||||
|
||||
export default function SandboxDetails({
|
||||
sandboxId,
|
||||
sandboxName,
|
||||
sandboxIP,
|
||||
sandboxStatus
|
||||
}: SandboxDetailsProps) {
|
||||
const [telemetry, setTelemetry] = useState<TelemetryData>({
|
||||
cpu: 0, memory: 0, disk: 0
|
||||
})
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [config, setConfig] = useState<SandboxConfig[]>([
|
||||
{ name: 'autoRestart', description: 'Automatically restart on failure', enabled: true },
|
||||
{ name: 'networkAccess', description: 'Allow network access', enabled: true },
|
||||
{ name: 'gpuEnabled', description: 'Enable GPU acceleration', enabled: true },
|
||||
{ name: 'persistentStorage', description: 'Use persistent storage', enabled: false },
|
||||
{ name: 'debugMode', description: 'Enable debug logging', enabled: false }
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (sandboxId) {
|
||||
fetchTelemetry()
|
||||
const interval = setInterval(fetchTelemetry, 5000)
|
||||
return () => clearInterval(interval)
|
||||
}
|
||||
}, [sandboxId])
|
||||
|
||||
const fetchTelemetry = async () => {
|
||||
if (!sandboxId) return
|
||||
setLoading(true)
|
||||
try {
|
||||
const response = await fetch('/api/telemetry/combined')
|
||||
const data = await response.json()
|
||||
setTelemetry(data)
|
||||
} catch (error) {
|
||||
console.error('Error fetching telemetry:', error)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleConfig = (name: string) => {
|
||||
setConfig(config.map(item =>
|
||||
item.name === name ? { ...item, enabled: !item.enabled } : item
|
||||
))
|
||||
}
|
||||
|
||||
if (!sandboxId) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<div className="text-center">
|
||||
<svg className="w-16 h-16 mx-auto mb-4 text-[var(--foreground-dim)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={1.5} d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
|
||||
</svg>
|
||||
<h3 className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">Select a Sandbox</h3>
|
||||
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
||||
Choose a sandbox from the menu to view details
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header - Technical Panel */}
|
||||
<div className="panel p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h2 className="text-lg font-mono font-semibold text-[var(--foreground)] uppercase tracking-tight">
|
||||
{sandboxName}
|
||||
</h2>
|
||||
<div className="flex items-center gap-4 mt-3">
|
||||
<span className="text-xs text-[var(--foreground-dim)] font-mono">
|
||||
IP: {sandboxIP}
|
||||
</span>
|
||||
<span className={`px-2 py-0.5 rounded-sm text-[10px] font-mono uppercase ${
|
||||
sandboxStatus === 'running'
|
||||
? 'bg-[var(--status-running)] text-white'
|
||||
: 'bg-[var(--status-pending)] text-white'
|
||||
}`}>
|
||||
{sandboxStatus?.toUpperCase() || 'UNKNOWN'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">Running</p>
|
||||
<p className="text-xs font-mono text-[var(--nvidia-green)]">NEMOSHELL</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Telemetry Grid - Technical */}
|
||||
<div className="panel p-6">
|
||||
<h3 className="text-xs font-semibold text-[var(--foreground)] uppercase tracking-wider mb-4">
|
||||
TELEMETRY
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<CompactGauge
|
||||
value={telemetry.cpu}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="CPU"
|
||||
/>
|
||||
<CompactGauge
|
||||
value={telemetry.memory}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="MEMORY"
|
||||
/>
|
||||
<CompactGauge
|
||||
value={telemetry.disk}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="DISK"
|
||||
/>
|
||||
{telemetry.gpuMemoryUsed !== undefined && telemetry.gpuMemoryTotal && (
|
||||
<CompactGauge
|
||||
value={(telemetry.gpuMemoryUsed / telemetry.gpuMemoryTotal) * 100}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#0D47A1"
|
||||
label="GPU MEM"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{telemetry.gpuTemperature && (
|
||||
<div className="mt-4 metric p-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-xs text-[var(--foreground-dim)] uppercase tracking-wider">GPU Temperature</span>
|
||||
<span className="text-xl font-mono text-[var(--nvidia-green)]">
|
||||
{telemetry.gpuTemperature.toFixed(1)}°C
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] mt-4 text-right font-mono uppercase tracking-wider">
|
||||
Updated: {new Date(telemetry.timestamp || Date.now()).toLocaleTimeString()}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Configuration - Technical */}
|
||||
<div className="panel p-6">
|
||||
<h3 className="text-xs font-semibold text-[var(--foreground)] uppercase tracking-wider mb-4">
|
||||
SANDBOX CONFIGURATION
|
||||
</h3>
|
||||
<div className="space-y-2">
|
||||
{config.map((item) => (
|
||||
<label
|
||||
key={item.name}
|
||||
className="flex items-center justify-between p-3 rounded-sm hover:bg-[var(--background-tertiary)] transition-colors cursor-pointer border border-transparent hover:border-[var(--border-subtle)]"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={item.enabled}
|
||||
onChange={() => toggleConfig(item.name)}
|
||||
className="w-4 h-4 rounded-sm border-[var(--border-medium)] bg-[var(--metric-bg)] text-[var(--nvidia-green)] focus:ring-[var(--nvidia-green)] focus:ring-offset-0"
|
||||
/>
|
||||
<span className="text-sm font-mono text-[var(--foreground)]">
|
||||
{item.name.replace(/([A-Z])/g, ' $1').trim().toUpperCase()}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] text-right max-w-[180px]">
|
||||
{item.description}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
"use client"
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
interface Sandbox {
|
||||
id: string
|
||||
name: string
|
||||
namespace: string
|
||||
ip: string
|
||||
status: 'running' | 'pending' | 'stopped' | 'unknown'
|
||||
ready: boolean
|
||||
}
|
||||
|
||||
interface TelemetryData {
|
||||
cpu: number
|
||||
memory: number
|
||||
disk: number
|
||||
gpuMemoryUsed?: number
|
||||
gpuMemoryTotal?: number
|
||||
gpuTemperature?: number
|
||||
timestamp: string
|
||||
}
|
||||
|
||||
interface SandboxListProps {
|
||||
selectedSandbox: string | null
|
||||
onSandboxSelect: (id: string | null) => void
|
||||
isDestroyMode: boolean
|
||||
}
|
||||
|
||||
export default function SandboxList({
|
||||
selectedSandbox,
|
||||
onSandboxSelect,
|
||||
isDestroyMode
|
||||
}: SandboxListProps) {
|
||||
const [sandboxes, setSandboxes] = useState<Sandbox[]>([])
|
||||
const [telemetry, setTelemetry] = useState<TelemetryData>({
|
||||
cpu: 0, memory: 0, disk: 0, timestamp: new Date().toISOString()
|
||||
})
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
fetchSandboxes()
|
||||
const interval = setInterval(fetchSandboxes, 10000)
|
||||
return () => clearInterval(interval)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedSandbox) {
|
||||
fetchTelemetry()
|
||||
const interval = setInterval(fetchTelemetry, 5000)
|
||||
return () => clearInterval(interval)
|
||||
}
|
||||
}, [selectedSandbox])
|
||||
|
||||
const fetchSandboxes = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/telemetry/real')
|
||||
const data = await response.json()
|
||||
|
||||
const sandboxList = (data.pods?.items || [])
|
||||
.filter((pod: any) => pod.metadata?.namespace === 'agent-sandbox-system')
|
||||
.map((pod: any) => ({
|
||||
id: pod.metadata?.name || 'unknown',
|
||||
name: pod.metadata?.name || 'Unknown Sandbox',
|
||||
namespace: pod.metadata?.namespace || 'unknown',
|
||||
ip: pod.status?.podIP || 'N/A',
|
||||
status: pod.status?.phase === 'Running' ? 'running' :
|
||||
pod.status?.phase === 'Pending' ? 'pending' :
|
||||
pod.status?.phase === 'Stopped' ? 'stopped' : 'unknown' as const,
|
||||
ready: pod.status?.conditions?.find((c: any) => c.type === 'Ready')?.status === 'True'
|
||||
}))
|
||||
|
||||
setSandboxes(sandboxList)
|
||||
setLoading(false)
|
||||
} catch (error) {
|
||||
console.error('Error fetching sandboxes:', error)
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchTelemetry = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/telemetry/combined')
|
||||
const data = await response.json()
|
||||
setTelemetry(data)
|
||||
} catch (error) {
|
||||
console.error('Error fetching telemetry:', error)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-64">
|
||||
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">
|
||||
INITIALIZING...
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{sandboxes.length === 0 ? (
|
||||
<div className="panel p-8 text-center">
|
||||
<svg className="w-12 h-12 mx-auto mb-4 text-[var(--foreground-dim)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={1.5} d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
|
||||
</svg>
|
||||
<h3 className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">No Sandboxes Detected</h3>
|
||||
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
||||
No sandboxes running in agent-sandbox-system namespace
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">
|
||||
{isDestroyMode ? 'SELECT SANDBOX TO DESTROY' : 'ACTIVE SANDBOXES'}
|
||||
</h3>
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] font-mono">
|
||||
REFRESH: 10s
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{sandboxes.map((sandbox) => (
|
||||
<button
|
||||
key={sandbox.id}
|
||||
onClick={() => onSandboxSelect(sandbox.id)}
|
||||
className={`p-4 rounded-sm text-left transition-all border-2 ${
|
||||
isDestroyMode
|
||||
? 'border-[var(--status-stopped)] hover:bg-[var(--status-stopped-bg)]'
|
||||
: selectedSandbox === sandbox.id
|
||||
? 'bg-[var(--nvidia-green)] text-white border-[var(--nvidia-green)]'
|
||||
: 'panel hover:border-[var(--nvidia-green)]'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<span className={`text-sm font-mono font-semibold truncate ${
|
||||
isDestroyMode ? 'text-[var(--status-stopped)]' : ''
|
||||
}`}>
|
||||
{sandbox.name}
|
||||
</span>
|
||||
<div className={`px-2 py-0.5 rounded-sm text-[10px] font-mono uppercase ${
|
||||
isDestroyMode
|
||||
? 'bg-[var(--status-stopped)] text-white animate-pulse'
|
||||
: sandbox.status === 'running' && sandbox.ready
|
||||
? 'bg-[var(--status-running)] text-white'
|
||||
: 'bg-[var(--status-pending)] text-white'
|
||||
}`}>
|
||||
{isDestroyMode ? 'DESTROY' : sandbox.status === 'running' && sandbox.ready ? 'RUNNING' : 'PENDING'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] uppercase">IP Address</span>
|
||||
<span className="text-xs font-mono">{sandbox.ip}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] uppercase">Namespace</span>
|
||||
<span className="text-xs font-mono truncate max-w-[120px]">{sandbox.namespace}</span>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Selected Sandbox Details - Technical Data Panel */}
|
||||
{!isDestroyMode && selectedSandbox && (
|
||||
<div className="panel p-6">
|
||||
<div className="flex items-center justify-between mb-6 pb-4 border-b border-[var(--border-subtle)]">
|
||||
<h4 className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">
|
||||
{sandboxes.find(s => s.id === selectedSandbox)?.name} — TELEMETRY
|
||||
</h4>
|
||||
<span className="text-[10px] text-[var(--foreground-dim)] font-mono">
|
||||
LIVE
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="metric p-4">
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">CPU</p>
|
||||
<p className="text-2xl font-mono text-[var(--nvidia-green)] mt-1">
|
||||
{telemetry.cpu.toFixed(1)}%
|
||||
</p>
|
||||
</div>
|
||||
<div className="metric p-4">
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">MEMORY</p>
|
||||
<p className="text-2xl font-mono text-[var(--nvidia-green)] mt-1">
|
||||
{telemetry.memory.toFixed(1)}%
|
||||
</p>
|
||||
</div>
|
||||
<div className="metric p-4">
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">DISK</p>
|
||||
<p className="text-2xl font-mono text-[var(--nvidia-green)] mt-1">
|
||||
{telemetry.disk.toFixed(1)}%
|
||||
</p>
|
||||
</div>
|
||||
{telemetry.gpuTemperature && (
|
||||
<div className="metric p-4">
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">GPU TEMP</p>
|
||||
<p className="text-2xl font-mono text-[var(--nvidia-green)] mt-1">
|
||||
{telemetry.gpuTemperature.toFixed(1)}°C
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
"use client"
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
interface Sandbox {
|
||||
id: string
|
||||
name: string
|
||||
ip: string
|
||||
status: 'running' | 'stopped' | 'unknown'
|
||||
}
|
||||
|
||||
interface SidebarProps {
|
||||
hostIP: string
|
||||
selectedSandbox: string | null
|
||||
onSandboxSelect: (id: string | null) => void
|
||||
isSubmenuOpen: boolean
|
||||
onToggleSubmenu: () => void
|
||||
isCreateMode: boolean
|
||||
isDestroyMode: boolean
|
||||
onCreateClick: () => void
|
||||
onDestroyClick: () => void
|
||||
onExitMode: () => void
|
||||
}
|
||||
|
||||
export default function Sidebar({
|
||||
hostIP,
|
||||
selectedSandbox,
|
||||
onSandboxSelect,
|
||||
isSubmenuOpen,
|
||||
onToggleSubmenu,
|
||||
isCreateMode,
|
||||
isDestroyMode,
|
||||
onCreateClick,
|
||||
onDestroyClick,
|
||||
onExitMode
|
||||
}: SidebarProps) {
|
||||
const [sandboxes, setSandboxes] = useState<Sandbox[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
const fetchSandboxes = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/telemetry/real')
|
||||
const data = await response.json()
|
||||
|
||||
const items = data?.pods?.items || []
|
||||
if (!Array.isArray(items)) {
|
||||
setSandboxes([])
|
||||
return
|
||||
}
|
||||
|
||||
const sandboxList = items
|
||||
.filter((pod: any) => pod?.metadata?.namespace === 'agent-sandbox-system')
|
||||
.map((pod: any) => ({
|
||||
id: pod.metadata?.name || 'unknown',
|
||||
name: pod.metadata?.name || 'Unknown Sandbox',
|
||||
ip: pod.status?.podIP || 'N/A',
|
||||
status: pod.status?.phase === 'Running' ? 'running' :
|
||||
pod.status?.phase === 'Pending' ? 'pending' :
|
||||
pod.status?.phase === 'Stopped' ? 'stopped' : 'unknown' as const
|
||||
}))
|
||||
|
||||
setSandboxes(sandboxList)
|
||||
} catch (error) {
|
||||
console.error('Error fetching sandboxes in Sidebar:', error)
|
||||
setSandboxes([])
|
||||
}
|
||||
}
|
||||
|
||||
if (isSubmenuOpen || isDestroyMode || isCreateMode) {
|
||||
fetchSandboxes()
|
||||
const interval = setInterval(fetchSandboxes, 10000)
|
||||
return () => clearInterval(interval)
|
||||
}
|
||||
}, [isSubmenuOpen, isDestroyMode, isCreateMode])
|
||||
return (
|
||||
<>
|
||||
{/* Main Sidebar */}
|
||||
<aside className="fixed left-0 top-0 h-screen w-64 bg-[var(--background-secondary)] border-r border-[var(--border-subtle)] flex flex-col z-20">
|
||||
{/* Host IP Header - Industrial Style */}
|
||||
<div className="p-4 border-b border-[var(--border-subtle)]">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-8 h-8 bg-[var(--nvidia-green)] rounded-sm flex items-center justify-center">
|
||||
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider font-semibold">Host</p>
|
||||
<p className="text-sm font-mono text-[var(--nvidia-green)] tracking-tight">{hostIP}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Navigation Menu - Technical */}
|
||||
<nav className="flex-1 p-2">
|
||||
<button
|
||||
onClick={onToggleSubmenu}
|
||||
className={`w-full flex items-center justify-between px-3 py-2 rounded-sm transition-colors ${
|
||||
isSubmenuOpen
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]'
|
||||
}`}
|
||||
>
|
||||
<span className="flex items-center gap-3">
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
|
||||
</svg>
|
||||
<span className="text-sm font-medium tracking-tight">Sandboxes</span>
|
||||
</span>
|
||||
<svg
|
||||
className={`w-4 h-4 transition-transform ${isSubmenuOpen ? 'rotate-90' : ''}`}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{/* Quick Actions - Technical Icons */}
|
||||
<div className="mt-4 space-y-1">
|
||||
<button
|
||||
onClick={onCreateClick}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors ${
|
||||
isCreateMode
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]'
|
||||
}`}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
<span className="text-sm">Create Sandbox</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onDestroyClick}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2 rounded-sm transition-colors ${
|
||||
isDestroyMode
|
||||
? 'bg-[var(--status-stopped)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)]'
|
||||
}`}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
||||
<span className="text-sm">Destroy Sandbox</span>
|
||||
</button>
|
||||
|
||||
{(isCreateMode || isDestroyMode) && (
|
||||
<button
|
||||
onClick={onExitMode}
|
||||
className="w-full flex items-center gap-3 px-3 py-2 rounded-sm bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:bg-[var(--background-panel)] transition-colors"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
<span className="text-sm">Cancel</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button className="w-full flex items-center gap-3 px-3 py-2 rounded-sm hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] transition-colors">
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
</svg>
|
||||
<span className="text-sm">Settings</span>
|
||||
</button>
|
||||
<button className="w-full flex items-center gap-3 px-3 py-2 rounded-sm hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] transition-colors">
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
|
||||
</svg>
|
||||
<span className="text-sm">Overview</span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{/* Footer - Technical */}
|
||||
<div className="p-4 border-t border-[var(--border-subtle)]">
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">OpenShell Control</p>
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] font-mono">v1.0.0</p>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* Slide-out Sandbox Submenu - Technical Data Panel */}
|
||||
<div
|
||||
className={`fixed left-64 top-0 h-screen w-72 bg-[var(--background)] border-r border-[var(--border-subtle)] transform transition-transform duration-200 ease-in-out z-10 ${
|
||||
isSubmenuOpen ? 'translate-x-0' : '-translate-x-full'
|
||||
}`}
|
||||
>
|
||||
<div className="p-4 border-b border-[var(--border-subtle)]">
|
||||
<h3 className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">
|
||||
{isCreateMode ? 'CREATE SANDBOX' : isDestroyMode ? 'DESTROY SANDBOX' : 'SANDBOXES'}
|
||||
</h3>
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] font-mono mt-1">
|
||||
{isDestroyMode && 'SELECT A SANDBOX BELOW'}
|
||||
{!isCreateMode && !isDestroyMode && `${sandboxes.filter(s => s.status === 'running').length} RUNNING / ${sandboxes.length} TOTAL`}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="p-2 overflow-y-auto h-[calc(100vh-80px)]">
|
||||
{isCreateMode ? (
|
||||
<div className="text-center py-8">
|
||||
<svg className="w-12 h-12 mx-auto mb-4 text-[var(--nvidia-green)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={1.5} d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
<p className="text-xs text-[var(--foreground-dim)]">CONFIGURATION PANEL WILL OPEN BELOW</p>
|
||||
</div>
|
||||
) : isDestroyMode ? (
|
||||
<div className="space-y-1">
|
||||
{sandboxes.length === 0 ? (
|
||||
<div className="text-center py-8">
|
||||
<p className="text-xs text-[var(--foreground-dim)]">NO SANDBOXES TO DESTROY</p>
|
||||
</div>
|
||||
) : (
|
||||
sandboxes.map((sandbox) => (
|
||||
<button
|
||||
key={sandbox.id}
|
||||
onClick={() => onSandboxSelect(sandbox.id)}
|
||||
className="w-full px-3 py-2 rounded-sm text-left transition-colors border-2 border-[var(--status-stopped)] hover:bg-[var(--status-stopped-bg)]"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="w-2 h-2 rounded-sm bg-[var(--status-stopped)] animate-pulse" />
|
||||
<span className="text-sm font-mono truncate text-[var(--status-stopped)]">{sandbox.name}</span>
|
||||
</div>
|
||||
<svg className="w-3 h-3 text-[var(--status-stopped)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] font-mono mt-1 ml-4">
|
||||
{sandbox.ip}
|
||||
</p>
|
||||
</button>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
<button
|
||||
onClick={() => onSandboxSelect(null)}
|
||||
className={`w-full px-3 py-2 rounded-sm text-left transition-colors ${
|
||||
selectedSandbox === null
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground)]'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm font-medium">ALL SANDBOXES</span>
|
||||
<svg className="w-3 h-3 opacity-75" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
{sandboxes.map((sandbox) => (
|
||||
<button
|
||||
key={sandbox.id}
|
||||
onClick={() => onSandboxSelect(sandbox.id)}
|
||||
className={`w-full px-3 py-2 rounded-sm text-left transition-colors ${
|
||||
selectedSandbox === sandbox.id
|
||||
? 'bg-[var(--nvidia-green)] text-white'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground)]'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className={`w-2 h-2 rounded-sm ${
|
||||
sandbox.status === 'running'
|
||||
? 'bg-[var(--status-running)]'
|
||||
: 'bg-[var(--status-pending)]'
|
||||
}`}
|
||||
/>
|
||||
<span className="text-sm font-mono truncate">{sandbox.name}</span>
|
||||
</div>
|
||||
<svg className="w-3 h-3 opacity-75" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] font-mono mt-1 ml-4">
|
||||
{sandbox.ip}
|
||||
</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
"use client"
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
interface GaugeProps {
|
||||
value: number
|
||||
max: number
|
||||
unit: string
|
||||
color: string
|
||||
label: string
|
||||
size?: 'small' | 'medium' | 'large'
|
||||
}
|
||||
|
||||
export default function SpeedometerGauge({
|
||||
value,
|
||||
max,
|
||||
unit,
|
||||
color,
|
||||
label,
|
||||
size = 'medium'
|
||||
}: GaugeProps) {
|
||||
const [percentage, setPercentage] = useState((value / max) * 100)
|
||||
const [animationValue, setAnimationValue] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
const target = (value / max) * 100
|
||||
setAnimationValue(target)
|
||||
}, [value, max])
|
||||
|
||||
const sizeMap = {
|
||||
small: { width: 150, height: 100, strokeWidth: 8, fontSize: 24 },
|
||||
medium: { width: 200, height: 140, strokeWidth: 10, fontSize: 32 },
|
||||
large: { width: 300, height: 200, strokeWidth: 15, fontSize: 48 }
|
||||
}
|
||||
|
||||
const s = sizeMap[size]
|
||||
|
||||
// Calculate gauge angle (0-180 degrees)
|
||||
const startAngle = 0.75 * Math.PI
|
||||
const endAngle = 2.25 * Math.PI
|
||||
const currentAngle = startAngle + (endAngle - startAngle) * (animationValue / 100)
|
||||
|
||||
const x1 = s.width / 2 + (s.width / 2 - 10) * Math.cos(startAngle)
|
||||
const y1 = s.height / 2 + (s.height / 2 - 10) * Math.sin(startAngle)
|
||||
const x2 = s.width / 2 + (s.width / 2 - 10) * Math.cos(currentAngle)
|
||||
const y2 = s.height / 2 + (s.height / 2 - 10) * Math.sin(currentAngle)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center">
|
||||
<svg width={s.width} height={s.height} className="transform -rotate-90">
|
||||
{/* Background circle */}
|
||||
<circle
|
||||
cx={s.width / 2}
|
||||
cy={s.height / 2}
|
||||
r={s.width / 2 - 10}
|
||||
fill="none"
|
||||
stroke={color === '#76B900' ? 'rgba(118, 185, 0, 0.1)' : 'rgba(13, 71, 161, 0.1)'}
|
||||
strokeWidth={s.strokeWidth}
|
||||
/>
|
||||
{/* Progress circle */}
|
||||
<circle
|
||||
cx={s.width / 2}
|
||||
cy={s.height / 2}
|
||||
r={s.width / 2 - 10}
|
||||
fill="none"
|
||||
stroke={color}
|
||||
strokeWidth={s.strokeWidth}
|
||||
strokeLinecap="round"
|
||||
strokeDasharray={2 * Math.PI * (s.width / 2 - 10)}
|
||||
strokeDashoffset={2 * Math.PI * (s.width / 2 - 10) * (1 - animationValue / 100)}
|
||||
style={{ transition: 'stroke-dashoffset 0.5s ease-out' }}
|
||||
/>
|
||||
</svg>
|
||||
<div className="text-center mt-4">
|
||||
<div
|
||||
className={`font-bold`}
|
||||
style={{ color: color, fontSize: `${s.fontSize}px` }}
|
||||
>
|
||||
{value.toFixed(1)}
|
||||
<span className="text-sm" style={{ color: color }}>
|
||||
{unit}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400" style={{ color: color }}>
|
||||
{label}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
"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<string | null>(null)
|
||||
const [telemetry, setTelemetry] = useState<TelemetryData>({
|
||||
cpu: 0,
|
||||
memory: 0,
|
||||
disk: 0,
|
||||
gpuMemoryUsed: 0,
|
||||
gpuMemoryTotal: 0,
|
||||
gpuTemperature: 0
|
||||
})
|
||||
const [sandboxes, setSandboxes] = useState<Sandbox[]>([])
|
||||
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 <div className="text-center text-gray-600 dark:text-gray-400">Loading telemetry...</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Sandbox Selection */}
|
||||
{sandboxes.length > 0 && (
|
||||
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
|
||||
<h3 className="text-lg font-semibold mb-3 dark:text-white">Select Sandbox</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
onClick={() => handleSandboxClick(null)}
|
||||
className={`px-4 py-2 rounded-lg ${
|
||||
!selectedSandbox
|
||||
? 'bg-blue-600 text-white'
|
||||
: 'bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200'
|
||||
}`}
|
||||
>
|
||||
Combined ({sandboxes.length} sandboxes)
|
||||
</button>
|
||||
{sandboxes.map((sandbox) => (
|
||||
<button
|
||||
key={sandbox.id}
|
||||
onClick={() => handleSandboxClick(sandbox.id)}
|
||||
className={`px-4 py-2 rounded-lg ${
|
||||
selectedSandbox === sandbox.id
|
||||
? 'bg-blue-600 text-white'
|
||||
: 'bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200'
|
||||
}`}
|
||||
>
|
||||
{sandbox.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Telemetry Gauges */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
<SpeedometerGauge
|
||||
value={telemetry.cpu}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="CPU Usage"
|
||||
size="large"
|
||||
/>
|
||||
<SpeedometerGauge
|
||||
value={telemetry.memory}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="Memory Usage"
|
||||
size="large"
|
||||
/>
|
||||
<SpeedometerGauge
|
||||
value={telemetry.disk}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#76B900"
|
||||
label="Disk Usage"
|
||||
size="large"
|
||||
/>
|
||||
{telemetry.gpuMemoryUsed !== undefined && telemetry.gpuMemoryTotal && (
|
||||
<SpeedometerGauge
|
||||
value={(telemetry.gpuMemoryUsed / telemetry.gpuMemoryTotal) * 100}
|
||||
max={100}
|
||||
unit="%"
|
||||
color="#0D47A1"
|
||||
label="GPU Memory"
|
||||
size="large"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Additional Metrics */}
|
||||
{telemetry.gpuTemperature && (
|
||||
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-6">
|
||||
<h3 className="text-lg font-semibold mb-4 dark:text-white">GPU Metrics</h3>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400">Temperature</p>
|
||||
<p className="text-2xl font-bold text-blue-600">
|
||||
{telemetry.gpuTemperature.toFixed(1)}°C
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400">Memory Used</p>
|
||||
<p className="text-2xl font-bold text-blue-600">
|
||||
{telemetry.gpuMemoryUsed.toFixed(1)} / {telemetry.gpuMemoryTotal.toFixed(1)} GB
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Selected Sandbox Info */}
|
||||
{selectedSandbox && (
|
||||
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
|
||||
<h3 className="text-lg font-semibold mb-2 dark:text-white">Selected Sandbox</h3>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400">
|
||||
IP: {sandboxes.find(s => s.id === selectedSandbox)?.ip}
|
||||
</p>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400">
|
||||
Status: {sandboxes.find(s => s.id === selectedSandbox)?.status}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user