added docker logs to diagnostic

This commit is contained in:
2026-03-12 01:34:16 +01:00
parent 2e4a12c812
commit 580141fa17
3 changed files with 119 additions and 2 deletions
+62
View File
@@ -409,6 +409,66 @@ async function testProxy(prompt) {
}
}
// ── Docker Container Logs ────────────────────────────────
const CONTAINER_MAP = {
gateway: "aria-core",
proxy: "aria-proxy",
bridge: "aria-bridge",
};
function fetchDockerLogs(tab, tail) {
const containerName = CONTAINER_MAP[tab];
if (!containerName) return;
const lines = parseInt(tail, 10) || 100;
const dockerPath = `/containers/${containerName}/logs?stdout=true&stderr=true&tail=${lines}&timestamps=true`;
return new Promise((resolve, reject) => {
const req = http.request(
{ socketPath: "/var/run/docker.sock", path: dockerPath, method: "GET" },
(res) => {
const chunks = [];
res.on("data", (chunk) => chunks.push(chunk));
res.on("end", () => {
// Docker log stream hat 8-byte Header pro Frame (stream type + size)
const raw = Buffer.concat(chunks);
const logLines = [];
let offset = 0;
while (offset < raw.length) {
if (offset + 8 > raw.length) break;
const size = raw.readUInt32BE(offset + 4);
if (offset + 8 + size > raw.length) break;
const line = raw.slice(offset + 8, offset + 8 + size).toString("utf-8").trimEnd();
if (line) logLines.push(line);
offset += 8 + size;
}
resolve(logLines);
});
}
);
req.on("error", (err) => reject(err));
req.end();
});
}
async function handleDockerLogs(ws, tab, tail) {
const containerName = CONTAINER_MAP[tab];
if (!containerName) {
ws.send(JSON.stringify({ type: "docker_logs", tab, error: `Unbekannter Tab: ${tab}` }));
return;
}
try {
log("info", "server", `Lade Docker-Logs: ${containerName} (tail ${tail || 100})`);
const lines = await fetchDockerLogs(tab, tail);
ws.send(JSON.stringify({ type: "docker_logs", tab, container: containerName, lines }));
} catch (err) {
log("error", "server", `Docker-Logs Fehler (${containerName}): ${err.message}`);
ws.send(JSON.stringify({ type: "docker_logs", tab, error: err.message }));
}
}
// ── Hilfsfunktionen ─────────────────────────────────────
function waitForMessage(ws, timeoutMs) {
@@ -462,6 +522,8 @@ wss.on("connection", (ws) => {
connectRVS();
} else if (msg.action === "test_proxy") {
testProxy(msg.text);
} else if (msg.action === "docker_logs") {
handleDockerLogs(ws, msg.tab, msg.tail);
}
} catch {}
});