diff --git a/crates/nexus-api/src/metrics.rs b/crates/nexus-api/src/metrics.rs index 09f1c19..a087418 100644 --- a/crates/nexus-api/src/metrics.rs +++ b/crates/nexus-api/src/metrics.rs @@ -47,6 +47,8 @@ pub struct InstanceSample { /// Gesamtwerte einer GPU (aus `nvidia-smi`). #[derive(Debug, Clone, PartialEq, serde::Serialize)] pub struct GpuSample { + pub name: String, + pub cuda_version: Option, pub index: u32, pub memory_used_mb: u64, pub memory_total_mb: u64, @@ -539,31 +541,76 @@ pub fn series_samples(metrics: &Metrics) -> Vec<(String, String, f64)> { out } -/// Liest die Ausgabe von `nvidia-smi --query-gpu=index,memory.used,memory.total, +/// Liest die Ausgabe von `nvidia-smi --query-gpu=index,name,memory.used,memory.total, /// utilization.gpu,temperature.gpu --format=csv,noheader,nounits`. pub fn parse_gpus(output: &str) -> Vec { output .lines() .filter_map(|line| { let f: Vec<&str> = line.split(',').map(str::trim).collect(); - if f.len() < 3 { + if f.len() < 4 { return None; } Some(GpuSample { index: f[0].parse().ok()?, - memory_used_mb: f[1].parse().ok()?, - memory_total_mb: f[2].parse().ok()?, - utilization_percent: f.get(3).and_then(|v| v.parse().ok()), - temperature_c: f.get(4).and_then(|v| v.parse().ok()), + name: f[1].to_string(), + cuda_version: None, + memory_used_mb: f[2].parse().ok()?, + memory_total_mb: f[3].parse().ok()?, + utilization_percent: f.get(4).and_then(|v| v.parse().ok()), + temperature_c: f.get(5).and_then(|v| v.parse().ok()), }) }) .collect() } +/// CUDA-Kompatibilitätsversion des Treibers aus dem Kopf der normalen Ausgabe. +/// Das ist nicht die Version eines installierten CUDA-Toolkits. +pub fn parse_cuda_version(output: &str) -> Option { + let value = output + .split_once("CUDA Version:")? + .1 + .split_whitespace() + .next()?; + let mut parts = value.split('.'); + let major = parts.next()?; + let minor = parts.next()?; + if parts.next().is_some() + || major.is_empty() + || minor.is_empty() + || !major.bytes().all(|b| b.is_ascii_digit()) + || !minor.bytes().all(|b| b.is_ascii_digit()) + { + return None; + } + Some(value.to_string()) +} + #[cfg(test)] mod tests { use super::*; + #[test] + fn gpu_namen_und_cuda_aus_beispielausgaben() { + let mut g = parse_gpus( + "0, NVIDIA GeForce RTX 3060, 9, 12288, 0, 35\n1, NVIDIA GeForce RTX 3060, 10, 12288, N/A, N/A\nkaputt\n", + ); + assert_eq!(g.len(), 2); + assert_eq!(g[0].name, "NVIDIA GeForce RTX 3060"); + assert_eq!(g[1].temperature_c, None); + let header = "| NVIDIA-SMI 580.95.05 Driver Version: 580.95.05 CUDA Version: 13.0 |"; + for gpu in &mut g { + gpu.cuda_version = parse_cuda_version(header); + } + assert_eq!(g[1].cuda_version.as_deref(), Some("13.0")); + let mut ohne_cuda = parse_gpus("0, NVIDIA GeForce RTX 3060, 9, 12288, 0, 35\n"); + ohne_cuda[0].cuda_version = parse_cuda_version("| NVIDIA-SMI 580.95.05 |\n| GPU Name |"); + assert_eq!(ohne_cuda[0].cuda_version, None); + assert_eq!(ohne_cuda[0].memory_total_mb, 12288); + assert_eq!(parse_cuda_version("| NVIDIA-SMI 580.95.05 |"), None); + assert_eq!(parse_cuda_version("CUDA Version: N/A |"), None); + } + #[test] fn anfragen_tokens_und_verteilung_erscheinen_im_textformat() { let m = Metrics::default(); @@ -617,7 +664,7 @@ mod tests { ram_mb: None, }]); m.set_gpus(parse_gpus( - "0, 11415, 12288, 87, 61\n1, 11391, 12288, 90, 63\n", + "0, NVIDIA GeForce RTX 3060, 11415, 12288, 87, 61\n1, NVIDIA GeForce RTX 3060, 11391, 12288, 90, 63\n", )); let text = m.render(); assert!(text.contains("nexus_instances_loaded 1")); @@ -635,7 +682,9 @@ mod tests { fn zeitreihen_zeilen_aus_gpus_und_instanzen() { let m = Metrics::default(); assert!(series_samples(&m).is_empty()); - m.set_gpus(parse_gpus("0, 11415, 12288, 87, 61\n")); + m.set_gpus(parse_gpus( + "0, NVIDIA GeForce RTX 3060, 11415, 12288, 87, 61\n", + )); m.set_instances(vec![InstanceSample { model: "glm".to_string(), engine: "maya".to_string(), @@ -663,7 +712,9 @@ mod tests { #[test] fn gpu_ausgabe_wird_gelesen_und_kaputtes_uebersprungen() { - let g = parse_gpus("0, 9, 12288, 0, 35\nkaputt\n1, 10, 12288\n"); + let g = parse_gpus( + "0, NVIDIA GeForce RTX 3060, 9, 12288, 0, 35\nkaputt\n1, NVIDIA GeForce RTX 3060, 10, 12288\n", + ); assert_eq!(g.len(), 2); assert_eq!(g[0].utilization_percent, Some(0)); assert_eq!(g[1].temperature_c, None); diff --git a/crates/nexus-api/src/runtime.rs b/crates/nexus-api/src/runtime.rs index 34b4a58..96d49f1 100644 --- a/crates/nexus-api/src/runtime.rs +++ b/crates/nexus-api/src/runtime.rs @@ -643,6 +643,14 @@ impl Shared { let load_ms = started.elapsed().as_millis() as u64; self.metrics .record_load(&plan.model, &plan.engine_name, load_ms); + if let Some(store) = self.store.get() + && let Err(e) = store + .lock() + .unwrap_or_else(|e| e.into_inner()) + .log_model_load(&plan.model) + { + tracing::error!(fehler = %e, "Ladevorgang konnte nicht gespeichert werden"); + } let usage = engine.measure(&handle).await; tracing::info!( ereignis = "instanz_bereit", @@ -777,14 +785,31 @@ async fn read_gpus(nvidia_smi: &Path) -> Vec { Duration::from_secs(5), tokio::process::Command::new(nvidia_smi) .args([ - "--query-gpu=index,memory.used,memory.total,utilization.gpu,temperature.gpu", + "--query-gpu=index,name,memory.used,memory.total,utilization.gpu,temperature.gpu", "--format=csv,noheader,nounits", ]) .output(), ) .await; match output { - Ok(Ok(out)) if out.status.success() => parse_gpus(&String::from_utf8_lossy(&out.stdout)), + Ok(Ok(out)) if out.status.success() => { + let mut gpus = parse_gpus(&String::from_utf8_lossy(&out.stdout)); + let header = tokio::time::timeout( + Duration::from_secs(5), + tokio::process::Command::new(nvidia_smi).output(), + ) + .await; + let cuda = match header { + Ok(Ok(out)) if out.status.success() => { + crate::metrics::parse_cuda_version(&String::from_utf8_lossy(&out.stdout)) + } + _ => None, + }; + for gpu in &mut gpus { + gpu.cuda_version = cuda.clone(); + } + gpus + } _ => Vec::new(), } } diff --git a/crates/nexus-api/src/ui.rs b/crates/nexus-api/src/ui.rs index 0f94a96..3f549e4 100644 --- a/crates/nexus-api/src/ui.rs +++ b/crates/nexus-api/src/ui.rs @@ -42,6 +42,7 @@ use nexus_store::{ApiKeyRecord, Rights, UserRecord, UserRole}; use crate::metrics::{GpuSample, InstanceSample}; use crate::state::AppState; +mod auswertung; mod benutzer; mod chat; mod engines; @@ -137,6 +138,7 @@ pub fn routes() -> Router> { .route("/ui/chat", get(chat::page)) .route("/ui/chat/senden", post(chat::send)) .route("/ui/chat.js", get(chat::script)) + .route("/ui/auswertung", get(auswertung::page)) .route("/ui/anfragen", get(requests_page)) .route("/ui/audit", get(audit_page)) .route("/ui/teil/uebersicht", get(overview_fragment)) @@ -442,6 +444,7 @@ pub(crate) fn layout(title: &str, active: &str, viewer: &Viewer, body: &str) -> ("/ui/warteschlange", "Warteschlange"), ("/ui/chat", "Chat"), ("/ui/anfragen", "Anfragen"), + ("/ui/auswertung", "Auswertung"), ("/ui/audit", "Audit"), ]; if viewer.admin() { @@ -870,8 +873,10 @@ fn gpu_table(gpus: &[GpuSample]) -> String { .checked_div(g.memory_total_mb) .unwrap_or(0) .min(100); + let description = format!("{} · {} GB · CUDA {}", esc(&g.name), g.memory_total_mb / 1024, + esc(g.cuda_version.as_deref().unwrap_or("nicht verfügbar"))); format!( - "GPU {}{bar}{} von {} ({pct} %)\ + "GPU {}
{description}{bar}{} von {} ({pct} %)\ {}{}", g.index, mb(Some(g.memory_used_mb)), @@ -1212,6 +1217,25 @@ async fn app_css() -> Response { mod tests { use super::*; + #[test] + fn gpu_tabelle_zeigt_name_speicher_und_optionale_cuda_version_maskiert() { + let mut gpu = GpuSample { + index: 0, + name: "NVIDIA GeForce RTX 3060".into(), + cuda_version: Some("13.0".into()), + memory_used_mb: 100, + memory_total_mb: 12288, + utilization_percent: None, + temperature_c: None, + }; + assert!(gpu_table(&[gpu.clone()]).contains("NVIDIA GeForce RTX 3060 · 12 GB · CUDA 13.0")); + gpu.cuda_version = None; + gpu.name = "