Feature: Sistema de tracking de sesiones RADIUS en tiempo real
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 30s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 30s
- Nueva tabla `sesiones` para historial persistente de conexiones - Job de detección de stale cada 2 min (10 min idle = desconectado) - Inicialización resiliente desde BD al arrancar el servidor - Nuevos endpoints: /api/sessions, /api/sessions/history, /api/sessions.csv - Nueva vista "Sesiones" en el dashboard con estadísticas - Historial integrado en UserCard y DispositivoCard - Estadísticas de bytes in/out y duración por sesión - Retención configurable de historial (90 días por defecto)
This commit is contained in:
49
postgres/init/03-sesiones.sql
Normal file
49
postgres/init/03-sesiones.sql
Normal file
@@ -0,0 +1,49 @@
|
||||
-- Session history table for tracking all RADIUS connections
|
||||
-- This table persists session data that was previously only in memory
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sesiones (
|
||||
id SERIAL PRIMARY KEY,
|
||||
|
||||
-- RADIUS session identifiers
|
||||
session_id VARCHAR(64) UNIQUE NOT NULL, -- Acct-Session-Id from FreeRADIUS
|
||||
username VARCHAR(64) NOT NULL, -- User-Name
|
||||
dispositivo_id INTEGER REFERENCES dispositivos(id) ON DELETE SET NULL,
|
||||
|
||||
-- NAS (Network Access Server) information
|
||||
nas_ip VARCHAR(45), -- NAS-IP-Address
|
||||
nas_id VARCHAR(64), -- NAS-Identifier
|
||||
calling_station_id VARCHAR(32), -- MAC address of client device
|
||||
called_station_id VARCHAR(64), -- SSID or AP identifier
|
||||
|
||||
-- Session timestamps
|
||||
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
ended_at TIMESTAMPTZ, -- NULL if session is active
|
||||
last_update TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
-- Session state: active, stopped, stale
|
||||
status VARCHAR(16) NOT NULL DEFAULT 'active',
|
||||
stop_reason VARCHAR(64), -- Acct-Terminate-Cause
|
||||
|
||||
-- Traffic statistics (from Interim-Updates and Stop)
|
||||
bytes_in BIGINT DEFAULT 0, -- Acct-Input-Octets
|
||||
bytes_out BIGINT DEFAULT 0, -- Acct-Output-Octets
|
||||
packets_in BIGINT DEFAULT 0, -- Acct-Input-Packets
|
||||
packets_out BIGINT DEFAULT 0, -- Acct-Output-Packets
|
||||
session_time INTEGER DEFAULT 0, -- Acct-Session-Time (seconds)
|
||||
|
||||
-- For stale detection
|
||||
interim_interval INTEGER -- Expected Acct-Interim-Interval
|
||||
);
|
||||
|
||||
-- Indexes for efficient queries
|
||||
CREATE INDEX IF NOT EXISTS idx_sesiones_username ON sesiones(username);
|
||||
CREATE INDEX IF NOT EXISTS idx_sesiones_dispositivo ON sesiones(dispositivo_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_sesiones_status ON sesiones(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_sesiones_started ON sesiones(started_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_sesiones_last_update ON sesiones(last_update);
|
||||
CREATE INDEX IF NOT EXISTS idx_sesiones_calling_station ON sesiones(calling_station_id);
|
||||
|
||||
-- Partial index for active sessions (frequently queried)
|
||||
CREATE INDEX IF NOT EXISTS idx_sesiones_active
|
||||
ON sesiones(username, dispositivo_id)
|
||||
WHERE status = 'active';
|
||||
Reference in New Issue
Block a user