feat(store): Schema 15 mit node_id, Rollups (5 Minuten, Stunden), Aufbewahrung und Verlaufsabfrage (#1197, DASH-R2)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GmHhg7qE8FdhchzsBrwgjZ
This commit is contained in:
2026-11-22 15:49:12 +01:00
parent 4ccf7b738c
commit aab3cd769e
6 changed files with 1384 additions and 11 deletions

View File

@ -168,9 +168,13 @@ impl Store {
rows.collect::<rusqlite::Result<Vec<_>>>().map_err(db)
}
/// Speichert Messwerte (Reihe, Ziel, Wert) mit der aktuellen Zeit in einem
/// Schritt.
pub fn record_samples(&mut self, samples: &[(String, String, f64)]) -> Result<()> {
/// Speichert Messwerte (Reihe, Ziel, Wert) des Knotens `node_id` mit der aktuellen Zeit
/// in einem Schritt.
pub fn record_samples(
&mut self,
node_id: &str,
samples: &[(String, String, f64)],
) -> Result<()> {
if samples.is_empty() {
return Ok(());
}
@ -179,11 +183,12 @@ impl Store {
{
let mut stmt = tx
.prepare(
"INSERT INTO metrik_probe (zeit, reihe, ziel, wert) VALUES (?1, ?2, ?3, ?4)",
"INSERT INTO metrik_probe (zeit, reihe, ziel, wert, node_id) VALUES (?1, ?2, ?3, ?4, ?5)",
)
.map_err(db)?;
for (series, target, value) in samples {
stmt.execute((&now, series, target, value)).map_err(db)?;
stmt.execute((&now, series, target, value, node_id))
.map_err(db)?;
}
}
tx.commit().map_err(db)
@ -549,13 +554,16 @@ mod tests {
fn messwerte_werden_gespeichert_gelesen_und_aufgeraeumt() {
let mut store = Store::open_in_memory().unwrap();
store
.record_samples(&[
("gpu_speicher_mb".to_string(), "gpu0".to_string(), 11411.0),
("gpu_speicher_mb".to_string(), "gpu1".to_string(), 9.0),
("instanz_vram_mb".to_string(), "glm".to_string(), 21906.0),
])
.record_samples(
"local",
&[
("gpu_speicher_mb".to_string(), "gpu0".to_string(), 11411.0),
("gpu_speicher_mb".to_string(), "gpu1".to_string(), 9.0),
("instanz_vram_mb".to_string(), "glm".to_string(), 21906.0),
],
)
.unwrap();
store.record_samples(&[]).unwrap();
store.record_samples("local", &[]).unwrap();
let gpu = store
.samples_since("gpu_speicher_mb", "2000-01-01T00:00:00Z")
.unwrap();