aien-sovereign-core
Autonomous sovereign intelligence engine and runtime core for NVIDIA DGX Spark
Brought by drakestapleton
aien-sovereign-core / crates / aien-cli / src / telemetry.rs
| 1 | use std::process::Command; |
| 2 | |
| 3 | #[derive(Debug, Clone, Default)] |
| 4 | pub struct GpuTelemetry { |
| 5 | pub name: String, |
| 6 | pub temp_c: u32, |
| 7 | pub used_mb: u64, |
| 8 | pub total_mb: u64, |
| 9 | pub util_pct: u32, |
| 10 | } |
| 11 | |
| 12 | pub fn get_gpu_telemetry() -> GpuTelemetry { |
| 13 | let output = Command::new("nvidia-smi") |
| 14 | .args(["--query-gpu=name,temperature.gpu,memory.used,memory.total,utilization.gpu", "--format=csv,noheader,nounits"]) |
| 15 | .output(); |
| 16 | |
| 17 | if let Ok(out) = output { |
| 18 | if out.status.success() { |
| 19 | let text = String::from_utf8_lossy(&out.stdout); |
| 20 | let parts: Vec<&str> = text.trim().split(",").map(|s| s.trim()).collect(); |
| 21 | if parts.len() >= 5 { |
| 22 | return GpuTelemetry { |
| 23 | name: parts[0].to_string(), |
| 24 | temp_c: parts[1].parse().unwrap_or(0), |
| 25 | used_mb: parts[2].parse().unwrap_or(0), |
| 26 | total_mb: parts[3].parse().unwrap_or(128000), |
| 27 | util_pct: parts[4].parse().unwrap_or(0), |
| 28 | }; |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | GpuTelemetry { |
| 34 | name: "NVIDIA GB10".to_string(), |
| 35 | temp_c: 36, |
| 36 | used_mb: 65400, |
| 37 | total_mb: 124620, |
| 38 | util_pct: 0, |
| 39 | } |
| 40 | } |