feat: Zeitreihen der Messwerte in SQLite (Schema 3), einmal pro Minute, 7 Tage Aufbewahrung (#1042)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -426,6 +426,32 @@ fn esc(value: &str) -> String {
|
||||
.replace('\n', "\\n")
|
||||
}
|
||||
|
||||
/// Die aktuellen Messwerte als Zeilen für die Zeitreihen in der Datenbank:
|
||||
/// (Reihe, Ziel, Wert).
|
||||
pub fn series_samples(metrics: &Metrics) -> Vec<(String, String, f64)> {
|
||||
let mut out = Vec::new();
|
||||
for g in metrics.gpus() {
|
||||
let target = format!("gpu{}", g.index);
|
||||
out.push((
|
||||
"gpu_speicher_mb".to_string(),
|
||||
target.clone(),
|
||||
g.memory_used_mb as f64,
|
||||
));
|
||||
if let Some(u) = g.utilization_percent {
|
||||
out.push(("gpu_auslastung_prozent".to_string(), target, u as f64));
|
||||
}
|
||||
}
|
||||
for i in metrics.instances() {
|
||||
if let Some(v) = i.vram_mb {
|
||||
out.push(("instanz_vram_mb".to_string(), i.model.clone(), v as f64));
|
||||
}
|
||||
if let Some(r) = i.ram_mb {
|
||||
out.push(("instanz_ram_mb".to_string(), i.model.clone(), r as f64));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Liest die Ausgabe von `nvidia-smi --query-gpu=index,memory.used,memory.total,
|
||||
/// utilization.gpu,temperature.gpu --format=csv,noheader,nounits`.
|
||||
pub fn parse_gpus(output: &str) -> Vec<GpuSample> {
|
||||
@ -518,6 +544,29 @@ mod tests {
|
||||
assert!(m.render().contains("nexus_instances_loaded 0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
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_instances(vec![InstanceSample {
|
||||
model: "glm".to_string(),
|
||||
engine: "maya".to_string(),
|
||||
instance_id: 1,
|
||||
vram_mb: Some(21_906),
|
||||
ram_mb: Some(65_139),
|
||||
}]);
|
||||
let rows = series_samples(&m);
|
||||
assert!(rows.contains(&("gpu_speicher_mb".to_string(), "gpu0".to_string(), 11415.0)));
|
||||
assert!(rows.contains(&(
|
||||
"gpu_auslastung_prozent".to_string(),
|
||||
"gpu0".to_string(),
|
||||
87.0
|
||||
)));
|
||||
assert!(rows.contains(&("instanz_vram_mb".to_string(), "glm".to_string(), 21906.0)));
|
||||
assert!(rows.contains(&("instanz_ram_mb".to_string(), "glm".to_string(), 65139.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn label_werte_werden_maskiert() {
|
||||
let m = Metrics::default();
|
||||
|
||||
Reference in New Issue
Block a user