feat: show shared engine health and hourly errors in overview (#1086)

This commit is contained in:
2026-11-17 13:14:53 +01:00
parent f53335d59e
commit a1e267dcd4
4 changed files with 188 additions and 14 deletions

View File

@ -192,6 +192,35 @@ pub struct Runtime {
/// Metriken des Gateways; Runtime füllt Ladezeiten, Fehlstarts und Messwerte.
pub metrics: Arc<Metrics>,
shared: Arc<Shared>,
health: tokio::sync::Mutex<HealthCache>,
}
#[derive(Default)]
struct HealthCache {
checked: Option<Instant>,
rows: Vec<EngineStatus>,
}
#[derive(Clone)]
pub struct EngineStatus {
pub name: String,
pub loaded: usize,
pub reachable: usize,
}
impl EngineStatus {
pub fn text(&self) -> String {
if self.loaded == 0 {
"nicht geladen".into()
} else if self.reachable == self.loaded {
format!("erreichbar ({}/{})", self.reachable, self.loaded)
} else {
format!(
"nicht vollständig erreichbar ({}/{})",
self.reachable, self.loaded
)
}
}
}
impl Runtime {
@ -219,7 +248,11 @@ impl Runtime {
gpu_warned: AtomicBool::new(false),
next_job: AtomicU64::new(1),
});
Self { metrics, shared }
Self {
metrics,
shared,
health: tokio::sync::Mutex::new(HealthCache::default()),
}
}
/// Gibt dem Scheduler Zugriff auf die Datenbank (Audit, gemessener VRAM).
@ -377,6 +410,40 @@ impl Runtime {
all
}
/// Gemeinsamer Health-Stand für beide Seiten. Gleichzeitige Aufrufe teilen
/// einen Abruf; frühestens fünf Sekunden nach dessen Ende erneut prüfen.
pub async fn engine_status(&self) -> Vec<EngineStatus> {
let mut cache = self.health.lock().await;
if cache
.checked
.is_some_and(|at| at.elapsed() < Duration::from_secs(5))
{
return cache.rows.clone();
}
let running: Vec<_> = self.shared.lock().running.values().cloned().collect();
let mut rows = Vec::new();
for (name, _, _) in self.engine_overview() {
let mut row = EngineStatus {
name,
loaded: 0,
reachable: 0,
};
for r in running.iter().filter(|r| r.engine_name == row.name) {
row.loaded += 1;
if matches!(
tokio::time::timeout(Duration::from_secs(2), r.engine.health(&r.handle)).await,
Ok(Health::Ready)
) {
row.reachable += 1;
}
}
rows.push(row);
}
cache.checked = Some(Instant::now());
cache.rows = rows.clone();
rows
}
/// Sucht, was die Engine selbst auf der Platte hat (nur lesend). Die Suche
/// bleibt in den Ordnern, die in der Konfiguration der Engine stehen.
pub async fn discover(