Implementierung von Lebenszyklusprotokollierung und Serverstartstatistiken
All checks were successful
Deploy SingleChat / deploy (push) Successful in 48s
All checks were successful
Deploy SingleChat / deploy (push) Successful in 48s
This commit is contained in:
@@ -2,6 +2,7 @@ import crypto from 'crypto';
|
||||
import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import axios from 'axios';
|
||||
import { getServerStartStats } from './server-lifecycle.js';
|
||||
|
||||
const TIMEOUT_SECONDS = 1800; // 30 Minuten
|
||||
const MAX_ACTIVE_VIDEO_CONNECTIONS = 3;
|
||||
@@ -609,27 +610,6 @@ function logClientLogin(client, __dirname) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkAndLogStart(__dirname) {
|
||||
try {
|
||||
const logsDir = join(__dirname, '../logs');
|
||||
// Erstelle logs-Verzeichnis falls es nicht existiert
|
||||
if (!existsSync(logsDir)) {
|
||||
try {
|
||||
mkdirSync(logsDir, { recursive: true });
|
||||
console.log(`[Log] Logs-Verzeichnis erstellt: ${logsDir}`);
|
||||
} catch (mkdirError) {
|
||||
console.error(`[Log] Fehler beim Erstellen des Logs-Verzeichnisses: ${mkdirError.message}`);
|
||||
return; // Beende Funktion, wenn Verzeichnis nicht erstellt werden kann
|
||||
}
|
||||
}
|
||||
const logPath = join(logsDir, 'starts.log');
|
||||
const logEntry = `${new Date().toISOString()}\n`;
|
||||
appendFileSync(logPath, logEntry, 'utf-8');
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Loggen des Starts:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
export function setupBroadcast(io, __dirname) {
|
||||
// Länderliste beim Start laden
|
||||
let countriesMap = {};
|
||||
@@ -728,23 +708,8 @@ export function setupBroadcast(io, __dirname) {
|
||||
.slice(0, limit);
|
||||
}
|
||||
|
||||
function readStartsLogStats() {
|
||||
const path = join(ensureLogsDir(__dirname), 'starts.log');
|
||||
if (!existsSync(path)) {
|
||||
return { count: 0, first: null, last: null };
|
||||
}
|
||||
const lines = readFileSync(path, 'utf-8')
|
||||
.split('\n')
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean);
|
||||
if (lines.length === 0) {
|
||||
return { count: 0, first: null, last: null };
|
||||
}
|
||||
return { count: lines.length, first: lines[0], last: lines[lines.length - 1] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Sammelt alle verfügbaren Kennzahlen: Live-Server, starts.log, vollständige Auswertung von logins.log
|
||||
* Sammelt alle verfügbaren Kennzahlen: Live-Server, echte Serverstarts und vollständige Login-Auswertung.
|
||||
* (entspricht inhaltlich den /stat-Unterbefehlen in einer Tabelle).
|
||||
*/
|
||||
function buildFullAllStatsRows(records) {
|
||||
@@ -763,7 +728,7 @@ export function setupBroadcast(io, __dirname) {
|
||||
totalMessages += Array.isArray(msgs) ? msgs.length : 0;
|
||||
}
|
||||
|
||||
const starts = readStartsLogStats();
|
||||
const starts = getServerStartStats(__dirname);
|
||||
|
||||
push('— Live (Server) —', '');
|
||||
push('Nutzer mit Chat-Login und aktiver Verbindung', liveOnline);
|
||||
@@ -771,13 +736,17 @@ export function setupBroadcast(io, __dirname) {
|
||||
push('Client-Sitzungen im Speicher', clients.size);
|
||||
push('Unterhaltungen im Speicher (Paare)', conversations.size);
|
||||
push('Nachrichten-Einträge gesamt (RAM)', totalMessages);
|
||||
push('Server-Starts protokolliert (starts.log)', starts.count);
|
||||
push('Server-Starts protokolliert (server-lifecycle.jsonl)', starts.count);
|
||||
if (starts.first) {
|
||||
push('Erster Start (Timestamp)', starts.first);
|
||||
push('Erster Server-Start (Timestamp)', starts.first.timestamp);
|
||||
}
|
||||
if (starts.last) {
|
||||
push('Letzter Start (Timestamp)', starts.last);
|
||||
push('Letzter Server-Start (Timestamp)', starts.last.timestamp);
|
||||
push('Anlass des letzten Server-Starts', starts.last.reason);
|
||||
}
|
||||
starts.latest.forEach((start, index) => {
|
||||
push(`Server-Start ${index + 1} (UTC)`, `${start.timestamp} — ${start.reason}`);
|
||||
});
|
||||
|
||||
push('— Login-Protokoll (logins.log, UTC) —', '');
|
||||
if (records.length === 0) {
|
||||
@@ -887,7 +856,7 @@ export function setupBroadcast(io, __dirname) {
|
||||
['/stat ages', 'Jüngster und ältester Nutzer'],
|
||||
['/stat names', 'Häufigkeit der verwendeten Namen'],
|
||||
['/stat countries', 'Häufigkeit der Länder'],
|
||||
['/all-stats', 'Alle Kennzahlen: Live-Server + starts.log + komplette logins.log-Auswertung']
|
||||
['/all-stats', 'Alle Kennzahlen: Live-Server + echte Serverstarts + komplette Login-Auswertung']
|
||||
]);
|
||||
return;
|
||||
}
|
||||
@@ -1148,7 +1117,7 @@ export function setupBroadcast(io, __dirname) {
|
||||
['/logout-admin', 'Admin-/Command-Login beenden'],
|
||||
['/whoami-rights', 'Aktuelle Admin-Rechte anzeigen'],
|
||||
['/stat help', 'Hilfe zu Statistikbefehlen anzeigen'],
|
||||
['/all-stats', 'Alle Kennzahlen: Live-Server + starts.log + komplette logins.log-Auswertung'],
|
||||
['/all-stats', 'Alle Kennzahlen: Live-Server + echte Serverstarts + komplette Login-Auswertung'],
|
||||
['/kick <username>', 'Benutzer aus dem Chat werfen'],
|
||||
['/help oder /?', 'Diese Hilfe anzeigen']
|
||||
]);
|
||||
@@ -1670,7 +1639,6 @@ export function setupBroadcast(io, __dirname) {
|
||||
});
|
||||
|
||||
logClientLogin(client, __dirname);
|
||||
checkAndLogStart(__dirname);
|
||||
|
||||
// Benutzerliste an alle senden
|
||||
broadcastUserList();
|
||||
|
||||
Reference in New Issue
Block a user