feat: GPU-Name und CUDA-Version, Auswertung als Seite, Engines-Seite überarbeitet (#1087, #1088, #1091)
- #1087: nvidia-smi liefert den Produktnamen; CUDA-Kompatibilitätsversion aus dem Kopf von nvidia-smi. - #1088: Seite /ui/auswertung mit Zeitraum und Gruppierung; Ladevorgänge in lade_log (Migration 0006, Schema-Änderung, ältere Versionen öffnen die Datenbank danach nicht mehr). - #1091: Engines-Seite mit Hinweis zur Anmeldung der Engine-Oberfläche; Startkommando nur für Admins. Statuszeile fehlt (wartet auf #1086), Link zur Engine-Oberfläche fehlt noch. Geprüft: cargo fmt --check, clippy -D warnings, cargo test --workspace (258 bestanden). Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
106
crates/nexus-api/src/ui/auswertung.rs
Normal file
106
crates/nexus-api/src/ui/auswertung.rs
Normal file
@ -0,0 +1,106 @@
|
||||
//! Lesende Auswertung der gespeicherten Anfrage-Metadaten.
|
||||
use super::{esc, form_field, html, layout, opt, redirect, viewer};
|
||||
use crate::state::AppState;
|
||||
use axum::extract::{RawQuery, State};
|
||||
use axum::http::{HeaderMap, StatusCode};
|
||||
use axum::response::Response;
|
||||
use nexus_store::SummaryGroup;
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub(super) async fn page(
|
||||
State(state): State<Arc<AppState>>,
|
||||
headers: HeaderMap,
|
||||
RawQuery(query): RawQuery,
|
||||
) -> Response {
|
||||
let Some(viewer) = viewer(&state, &headers) else {
|
||||
return redirect("/ui/login");
|
||||
};
|
||||
let query = query.as_deref().unwrap_or("");
|
||||
let period = form_field(query.as_bytes(), "zeit").unwrap_or_else(|| "stunde".into());
|
||||
let grouping = form_field(query.as_bytes(), "gruppe").unwrap_or_else(|| "modell".into());
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
let since = match period.as_str() {
|
||||
"stunde" => now.saturating_sub(3600),
|
||||
"heute" => now / 86400 * 86400,
|
||||
"7tage" => now.saturating_sub(7 * 86400),
|
||||
"30tage" => now.saturating_sub(30 * 86400),
|
||||
_ => return html(StatusCode::BAD_REQUEST, "Ungültiger Zeitraum.".into()),
|
||||
};
|
||||
let group = match grouping.as_str() {
|
||||
"modell" => SummaryGroup::Model,
|
||||
"key" => SummaryGroup::Key,
|
||||
"benutzer" => SummaryGroup::User,
|
||||
_ => return html(StatusCode::BAD_REQUEST, "Ungültige Aufschlüsselung.".into()),
|
||||
};
|
||||
let since = nexus_core::iso8601_from_unix(since);
|
||||
let until = nexus_core::iso8601_from_unix(now + 1);
|
||||
let result = {
|
||||
let store = state.store();
|
||||
store
|
||||
.request_summary(&since, &until, group)
|
||||
.and_then(|rows| store.load_recording_since().map(|start| (rows, start)))
|
||||
};
|
||||
let (rows, start) = match result {
|
||||
Ok(result) => result,
|
||||
Err(e) => {
|
||||
tracing::error!(fehler = %e, "Auswertung konnte nicht gelesen werden");
|
||||
return html(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Die Auswertung konnte nicht gelesen werden.".into(),
|
||||
);
|
||||
}
|
||||
};
|
||||
let periods: String = [
|
||||
("stunde", "Letzte Stunde"),
|
||||
("heute", "Heute (UTC)"),
|
||||
("7tage", "7 Tage"),
|
||||
("30tage", "30 Tage"),
|
||||
]
|
||||
.iter()
|
||||
.map(|(value, label)| option(value, label, &period))
|
||||
.collect();
|
||||
let groups: String = [
|
||||
("modell", "Je Modell"),
|
||||
("key", "Je Modell und Key"),
|
||||
("benutzer", "Je Modell und Benutzer"),
|
||||
]
|
||||
.iter()
|
||||
.map(|(value, label)| option(value, label, &grouping))
|
||||
.collect();
|
||||
let body_rows: String = rows.iter().map(|r| format!(
|
||||
"<tr><td>{}</td><td>{}</td><td class=\"num\">{}</td><td class=\"num\">{}</td><td class=\"num\">{}</td><td class=\"num\">{}</td><td class=\"num\">{}</td></tr>",
|
||||
esc(r.model.as_deref().unwrap_or("Unbekannt oder gelöscht")), esc(r.actor.as_deref().unwrap_or("–")),
|
||||
r.requests, opt(r.tokens_in), opt(r.tokens_out), r.errors, opt(r.loads),
|
||||
)).collect();
|
||||
let body_rows = if body_rows.is_empty() {
|
||||
"<tr><td colspan=\"7\">Keine Daten für diese Auswahl.</td></tr>".into()
|
||||
} else {
|
||||
body_rows
|
||||
};
|
||||
let body = format!(
|
||||
"<form method=\"get\" action=\"/ui/auswertung\" class=\"zeile\"><label>Zeitraum <select name=\"zeit\">{periods}</select></label> \
|
||||
<label>Aufschlüsselung <select name=\"gruppe\">{groups}</select></label> <button type=\"submit\">Anzeigen</button></form>\
|
||||
<p>Ab {} (UTC). Die Auswertung reicht nur so weit zurück wie das aufbewahrte Anfrage-Log. \
|
||||
Tokens sind die Summen der von Engines gemeldeten Werte; fehlende Angaben zählen nicht mit. Fehler sind HTTP-Status ab 400.</p>\
|
||||
<p>Erfolgreiche Ladevorgänge werden seit {} (UTC) erfasst und wie das Anfrage-Log aufbewahrt. Historische Ladezahlen vor diesem Zeitpunkt sind nicht verfügbar; die Zahlen umfassen ausschließlich erfasste Starts. \
|
||||
Ladevorgänge sind nur je Modell bekannt, nicht je Key oder Benutzer. Die Aufschlüsselung nach Key bzw. Benutzer zeigt nur entsprechend zugeordnete Anfragen.</p>\
|
||||
<section class=\"card\"><div class=\"breit\"><table><thead><tr><th>Modell</th><th>Key / Benutzer</th><th>Anfragen</th><th>Tokens rein</th><th>Tokens raus</th><th>Fehler</th><th>Ladevorgänge (erfasst)</th></tr></thead><tbody>{body_rows}</tbody></table></div></section>",
|
||||
esc(&since),
|
||||
esc(&start),
|
||||
);
|
||||
html(
|
||||
StatusCode::OK,
|
||||
layout("Auswertung", "/ui/auswertung", &viewer, &body),
|
||||
)
|
||||
}
|
||||
|
||||
fn option(value: &str, label: &str, selected: &str) -> String {
|
||||
format!(
|
||||
"<option value=\"{value}\"{}>{label}</option>",
|
||||
if value == selected { " selected" } else { "" }
|
||||
)
|
||||
}
|
||||
@ -142,7 +142,8 @@ pub(super) async fn engines_page(
|
||||
None => None,
|
||||
};
|
||||
let rows = super::verwaltung::model_engine_names(&state);
|
||||
let view = state.runtime.scheduler_view();
|
||||
let mut summary = String::new();
|
||||
let mut searches = String::new();
|
||||
let cards: String = state
|
||||
.runtime
|
||||
.engine_overview()
|
||||
@ -153,11 +154,12 @@ pub(super) async fn engines_page(
|
||||
.filter(|(_, engine)| engine.as_deref() == Some(name.as_str()))
|
||||
.map(|(model, _)| model)
|
||||
.collect();
|
||||
let loaded = view
|
||||
.instances
|
||||
.iter()
|
||||
.filter(|i| models.iter().any(|m| **m == i.model))
|
||||
.count();
|
||||
let links: String = models.iter().map(|model| format!(
|
||||
"<a href=\"/ui/modelle#modell-{}\">{}</a> ",
|
||||
super::verwaltung::dialog_id(model), esc(model)
|
||||
)).collect();
|
||||
summary.push_str(&format!("<tr><th>{}</th><td>{}</td></tr>", esc(&name),
|
||||
if links.is_empty() { "Keine Modelle registriert.".into() } else { links }));
|
||||
let installed = match &start.executable {
|
||||
Some(path) if path.exists() => {
|
||||
"<span class=\"chip ok\">gefunden</span>".to_string()
|
||||
@ -190,53 +192,42 @@ pub(super) async fn engines_page(
|
||||
.iter()
|
||||
.map(|(k, v)| format!("<div><dt>{}</dt><dd class=\"pfad\">{}</dd></div>", esc(k), esc(v)))
|
||||
.collect();
|
||||
let start_details = if viewer.admin() {
|
||||
format!("<details><summary>Startkommando und Umgebung</summary><dl class=\"daten\">{exe}\
|
||||
<div class=\"breit-zeile\"><dt>Start</dt><dd><pre class=\"befehl\">{}</pre></dd></div>{env}{details}</dl></details>",
|
||||
if start.command.is_empty() { "Der Adapter nennt kein Startkommando.".into() } else { esc(&start.command) })
|
||||
} else { String::new() };
|
||||
if viewer.admin() {
|
||||
searches.push_str(&format!(
|
||||
"<section><h3>{}</h3><form method=\"get\" action=\"/ui/engines\">\
|
||||
<input type=\"hidden\" name=\"suche\" value=\"{}\">\
|
||||
<button class=\"sm\" type=\"submit\">Modelle suchen</button></form>{}</section>",
|
||||
esc(&name), esc(&name),
|
||||
match &searched {
|
||||
Some((engine, result, registered)) if *engine == name => found_block(&viewer, &name, result.clone(), registered),
|
||||
_ => String::new(),
|
||||
}));
|
||||
}
|
||||
format!(
|
||||
"<section class=\"card engine\"><div class=\"zeile\"><h2>{name}</h2>\
|
||||
<span class=\"chip accent\">{mode}</span>{installed}\
|
||||
<span class=\"rechts muted\">{n} Modelle registriert · {loaded} geladen</span></div>\
|
||||
<div class=\"chips\">{caps}</div>{search_button}\
|
||||
<dl class=\"daten\">{exe}\
|
||||
<div class=\"breit-zeile\"><dt>Start</dt><dd><pre class=\"befehl\">{command}</pre></dd></div>\
|
||||
{env}{details}</dl>{found}</section>",
|
||||
name = esc(&name),
|
||||
search_button = if viewer.admin() {
|
||||
format!(
|
||||
"<form class=\"zeile\" method=\"get\" action=\"/ui/engines\">\
|
||||
<input type=\"hidden\" name=\"suche\" value=\"{}\">\
|
||||
<button class=\"sm\" type=\"submit\">Modelle suchen</button></form>",
|
||||
esc(&name)
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
},
|
||||
found = match &searched {
|
||||
Some((engine, result, registered)) if *engine == name => format!(
|
||||
"<h3>Gefundene Modelle</h3>{}",
|
||||
found_block(&viewer, &name, result.clone(), registered)
|
||||
),
|
||||
_ => String::new(),
|
||||
},
|
||||
mode = mode_text(info.mode),
|
||||
n = models.len(),
|
||||
caps = capability_chips(&info.capabilities),
|
||||
command = if start.command.is_empty() {
|
||||
"(Der Adapter nennt kein Startkommando.)".to_string()
|
||||
} else {
|
||||
esc(&start.command)
|
||||
},
|
||||
<span class=\"rechts muted\">{n} Modelle registriert</span></div>\
|
||||
<div class=\"chips\">{caps}</div>{start_details}</section>",
|
||||
name = esc(&name), mode = mode_text(info.mode), n = models.len(), caps = capability_chips(&info.capabilities),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let search_section = if viewer.admin() {
|
||||
format!(
|
||||
"<section class=\"card\"><h2>Modelle suchen und registrieren</h2>{searches}</section>"
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let body = format!(
|
||||
"{notice}<p class=\"klein\">So startet das Gateway die Engines. Angezeigt wird die Kommandozeile mit Platzhaltern in spitzen Klammern; \
|
||||
Port, Modelldatei und GPUs setzt das Gateway beim Start ein. Geändert wird in der Konfiguration (<code>config.toml</code>), \
|
||||
Startprofile in der Oberfläche folgen später.{search_hint}</p>{cards}",
|
||||
"{notice}<section class=\"card\"><h2>Engines und Modelle</h2><table><thead><tr><th>Engine</th><th>Modelle</th></tr></thead><tbody>{summary}</tbody></table></section>\
|
||||
{cards}{search_section}<p class=\"klein\">Die Oberfläche der Engine hat keine eigene Anmeldung, das Gateway kontrolliert sie nicht.</p>",
|
||||
notice = notice(query.as_deref()),
|
||||
search_hint = if viewer.admin() {
|
||||
" Mit „Modelle suchen“ findet das Gateway, was die Engine in den Ordnern ihrer Konfiguration hat, und trägt es auf Wunsch ein."
|
||||
} else {
|
||||
""
|
||||
},
|
||||
);
|
||||
html(
|
||||
StatusCode::OK,
|
||||
|
||||
@ -194,8 +194,9 @@ fn models_table(state: &AppState, viewer: &Viewer) -> String {
|
||||
),
|
||||
(None, None) => "<span class=\"muted\">–</span>".to_string(),
|
||||
};
|
||||
let row_id = format!("modell-{}", dialog_id(&m.name));
|
||||
format!(
|
||||
"<tr><td class=\"name\">{}</td><td>{}</td><td>{}</td><td>{}</td><td class=\"num\">{context}</td>\
|
||||
"<tr id=\"{row_id}\"><td class=\"name\">{}</td><td>{}</td><td>{}</td><td>{}</td><td class=\"num\">{context}</td>\
|
||||
<td class=\"num\">{memory}</td><td>{state_chip}</td>{actions}</tr>",
|
||||
esc(&m.name),
|
||||
m.engine
|
||||
|
||||
Reference in New Issue
Block a user