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:
98
crates/nexus-store/src/reihen.rs
Normal file
98
crates/nexus-store/src/reihen.rs
Normal file
@ -0,0 +1,98 @@
|
||||
//! Statische Tabelle der Messreihen: Einheit, Art der Aggregation, Anzeigename.
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
/// Wie Werte einer Reihe über die Zeit zusammengefasst werden sollen.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Aggregation {
|
||||
Mittel,
|
||||
Summe,
|
||||
Max,
|
||||
}
|
||||
|
||||
impl Aggregation {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Aggregation::Mittel => "mittel",
|
||||
Aggregation::Summe => "summe",
|
||||
Aggregation::Max => "max",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Eigenschaften einer Messreihe.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
pub struct ReiheInfo {
|
||||
pub name: &'static str,
|
||||
pub einheit: &'static str,
|
||||
pub aggregation: Aggregation,
|
||||
pub anzeigename: &'static str,
|
||||
}
|
||||
|
||||
const fn r(
|
||||
name: &'static str,
|
||||
einheit: &'static str,
|
||||
aggregation: Aggregation,
|
||||
anzeigename: &'static str,
|
||||
) -> ReiheInfo {
|
||||
ReiheInfo {
|
||||
name,
|
||||
einheit,
|
||||
aggregation,
|
||||
anzeigename,
|
||||
}
|
||||
}
|
||||
|
||||
use Aggregation::{Max, Mittel, Summe};
|
||||
|
||||
static REIHEN: &[ReiheInfo] = &[
|
||||
r("gpu_speicher_mb", "MB", Mittel, "GPU-Speicher"),
|
||||
r("gpu_auslastung_prozent", "%", Mittel, "GPU-Auslastung"),
|
||||
r("gpu_leistung_w", "W", Mittel, "GPU-Leistung"),
|
||||
r("instanz_vram_mb", "MB", Mittel, "VRAM je Modell"),
|
||||
r("instanz_ram_mb", "MB", Mittel, "RAM je Modell"),
|
||||
r("cpu_auslastung_prozent", "%", Mittel, "CPU-Auslastung"),
|
||||
r("ram_belegt_mb", "MB", Mittel, "RAM belegt"),
|
||||
r("queue_laenge", "Anzahl", Max, "Warteschlange"),
|
||||
r("anfragen_pro_min", "1/min", Summe, "Anfragen pro Minute"),
|
||||
r("fehler_pro_min", "1/min", Summe, "Fehler pro Minute"),
|
||||
r("durchsatz_tokens_s", "Tokens/s", Mittel, "Durchsatz"),
|
||||
];
|
||||
|
||||
/// Alle bekannten Messreihen in fester Reihenfolge.
|
||||
pub fn alle_reihen() -> &'static [ReiheInfo] {
|
||||
REIHEN
|
||||
}
|
||||
|
||||
/// Die Eigenschaften einer Reihe; `None` bei unbekanntem Namen.
|
||||
pub fn reihe_info(name: &str) -> Option<ReiheInfo> {
|
||||
REIHEN.iter().find(|i| i.name == name).copied()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn tabelle_ist_vollstaendig_und_eindeutig() {
|
||||
assert_eq!(alle_reihen().len(), 11);
|
||||
for (i, a) in alle_reihen().iter().enumerate() {
|
||||
assert!(
|
||||
alle_reihen()[i + 1..].iter().all(|b| b.name != a.name),
|
||||
"doppelt: {}",
|
||||
a.name
|
||||
);
|
||||
}
|
||||
let q = reihe_info("queue_laenge").unwrap();
|
||||
assert_eq!((q.einheit, q.aggregation), ("Anzahl", Aggregation::Max));
|
||||
let a = reihe_info("anfragen_pro_min").unwrap();
|
||||
assert_eq!((a.einheit, a.aggregation), ("1/min", Aggregation::Summe));
|
||||
assert_eq!(
|
||||
reihe_info("gpu_speicher_mb").unwrap().aggregation,
|
||||
Aggregation::Mittel
|
||||
);
|
||||
assert!(reihe_info("gibt_es_nicht").is_none());
|
||||
assert!(reihe_info("gpu_speicher_mb; DROP TABLE x").is_none());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user