How niklasfrick/spark-dashboard works
Purpose and Entry Points
Spark Dashboard is a Linux/NVIDIA monitoring service for host hardware and vLLM inference engines. The Rust binary is the production entry point; it serves the embedded React dashboard, REST configuration API, and WebSockets. Key paths: src/main.rs, src/server.rs, src/cli/service.rs.
Backend Runtime and Orchestration
main parses CLI/environment configuration, initializes shared state, and starts independent Tokio collector tasks plus Axum. Collectors publish snapshots through a bounded broadcast channel so slow/disconnected browser clients do not control collection. Key paths: src/main.rs, src/metrics/mod.rs, src/engines/mod.rs.
Host Metrics Collection
The hardware collector polls at a configurable interval (default 1 second), assembling CPU, memory, disk, network, and multi-GPU snapshots. GPU collection relies on NVIDIA/NVML; CPU/system counters use Linux-facing sources such as sysinfo/procfs. It also supports GPU simulation for development and unified-memory detection. Key paths: src/metrics/gpu.rs, src/metrics/cpu.rs, src/metrics/memory.rs.
Engine Discovery and vLLM Monitoring
Engine collection is separate from hardware collection. It discovers vLLM processes and, when Docker socket access exists, vLLM containers; explicit engine URLs can override discovery. The vLLM adapter polls Prometheus-format metrics and tracks engine lifecycle/state, model metadata, latency, throughput, requests, and cache metrics. Key paths: src/engines/detector.rs, src/engines/vllm.rs, src/engines/prometheus.rs.
Delivery, API, and Persistence Boundaries
Axum exposes /ws for metric streams and /api/dashboard for a shared dashboard document. The backend treats configuration as opaque, size-limited bytes; config_store handles atomic persistence and read-only-state behavior. Optional /ws/logs uses Docker APIs to fan out logs only for tracked container engines. Production static assets are embedded; unmatched API routes remain API 404s rather than falling through to the SPA. Key paths: src/server.rs, src/ws.rs, src/config_store.rs.
React Dashboard Data Flow
The Vite/React client opens the WebSocket, reconnects on failure, batches received snapshots, and retains rolling history in circular buffers. Dashboard renders host metrics, multi-engine aggregate/per-engine tabs, charts, gauges, controls, and optional logs. Dashboard layout/configuration is loaded and saved through the REST API, with schema/migration/preset logic entirely client-side. Key paths: frontend/src/main.tsx, frontend/src/hooks/useMetrics.ts, frontend/src/components/views/Dashboard.tsx.
Deployment and External Dependencies
Production supports a systemd-managed host binary and a GPU-enabled Docker image. The systemd service provisions a restricted service user and persistent state directory; Docker requires NVIDIA Container Toolkit and optionally mounts /var/run/docker.sock for container discovery/logs. External integrations are NVIDIA drivers/NVML, Docker Engine API via Bollard, vLLM HTTP/Prometheus endpoints, and optional authenticated engine APIs. Key paths: deploy/host/systemd/spark-dashboard.service, deploy/docker/Dockerfile, deploy/docker/docker-compose.yml.
Main entry points: main.rs Rust entry point · metrics/mod.rs Hardware collector · engines/mod.rs Engine collector · server.rs Axum server
Components 23
Rust backend
- Rust entry point · Parses configuration and starts collectors and Axum.
src/main.rs - Service CLI
src/cli/service.rs - Axum server · Serves APIs, WebSockets, and embedded assets.
src/server.rs - Snapshot broadcast · Decouples collectors from browser clients.
src/metrics/mod.rs - Hardware collector · Produces periodic host and GPU snapshots.
src/metrics/mod.rs - GPU metrics · Collects multi-GPU data, simulation, and unified-memory status.
src/metrics/gpu.rs - CPU and memory metrics · Reads CPU, memory, disk, and network counters.
src/metrics/cpu.rs - Memory metrics
src/metrics/memory.rs - Engine collector · Discovers and monitors inference engines independently of host metrics.
src/engines/mod.rs - vLLM discovery · Finds processes and Docker containers; explicit URLs override discovery.
src/engines/detector.rs - vLLM adapter · Tracks lifecycle, model, latency, throughput, requests, and cache data.
src/engines/vllm.rs - Prometheus polling
src/engines/prometheus.rs - Dashboard config store · Stores opaque size-limited bytes and handles read-only state.
src/config_store.rs - Metrics WebSocket
src/ws.rs
React dashboard
- React client
frontend/src/main.tsx - Metrics data hook · Reconnects, batches snapshots, and maintains rolling circular history.
frontend/src/hooks/useMetrics.ts - Dashboard UI · Renders host and engine views, charts, controls, and optional logs.
frontend/src/components/views/Dashboard.tsx
Deployment
- Systemd host service · Runs a restricted service user with persistent state.
deploy/host/systemd/spark-dashboard.service - GPU Docker deployment · Uses NVIDIA runtime and can mount the Docker socket.
deploy/docker/Dockerfile - Docker Compose
deploy/docker/docker-compose.yml
Other components
- NVIDIA drivers / NVML
- Docker Engine API · Supports container discovery and tracked-engine logs.
- vLLM endpoints · HTTP and Prometheus endpoints may require authentication.
Connections 26
- Service CLI → Rust entry point: manages
- Rust entry point → Hardware collector: starts
- Rust entry point → Engine collector: starts
- Rust entry point → Axum server: starts
- Hardware collector → GPU metrics: collects
- Hardware collector → CPU and memory metrics: collects
- CPU and memory metrics → Memory metrics: includes
- GPU metrics → NVIDIA drivers / NVML: uses
- Hardware collector → Snapshot broadcast: publishes snapshots
- Engine collector → vLLM discovery: discovers
- vLLM discovery → Docker Engine API: inspects containers
- Engine collector → vLLM adapter: monitors engines
- vLLM adapter → Prometheus polling: uses
- Prometheus polling → vLLM endpoints: polls
- Engine collector → Snapshot broadcast: publishes snapshots
- Axum server → Metrics WebSocket: exposes /ws
- Snapshot broadcast → Metrics WebSocket: streams snapshots
- Axum server → Dashboard config store: serves /api/dashboard
- React client → Metrics data hook: initializes
- Metrics data hook → Metrics WebSocket: connects /ws
- Metrics data hook → Dashboard UI: supplies history
- Dashboard UI → Axum server: loads and saves config
- Systemd host service → Rust entry point: runs
- GPU Docker deployment → Rust entry point: packages
- Docker Compose → GPU Docker deployment: deploys
- GPU Docker deployment → Docker Engine API: optional socket mount