Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GmHhg7qE8FdhchzsBrwgjZ
99 lines
2.9 KiB
Rust
99 lines
2.9 KiB
Rust
//! 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};
|
|
|
|
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", Mittel, "Anfragen pro Minute"),
|
|
r("fehler_pro_min", "1/min", Mittel, "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::Mittel));
|
|
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());
|
|
}
|
|
}
|