Add the staff stats dashboard

Backend: GET /api/stats/ (staff only) gathers psutil CPU/memory counters,
nvidia-smi GPU stats, the cached disk numbers and the running/finished
download + match jobs. Root logging now also writes a rotating file
(backend/logs/j621.log) so the dashboard can tail it, and psutil joins the
requirements. The storage payload computation is shared with the existing
storage endpoint.

Frontend: a /stats route + Stats nav entry for staff, polling every 2 s —
per-core CPU bars, memory and swap, GPUs (utilization, VRAM, temperature),
disk with the media/temp breakdown, active jobs with progress bars,
recently finished jobs with summaries, and the log tail with level colours
and an auto-scroll toggle. Section 4 of the roadmap is complete.
This commit is contained in:
2026-09-17 21:36:33 -05:00
parent 0fcc4e518a
commit b024fc52d7
11 changed files with 808 additions and 62 deletions
+27 -1
View File
@@ -1,10 +1,12 @@
import time
from django.conf import settings
from rest_framework.permissions import AllowAny
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from . import stats
from .system_info import get_os_info
@@ -40,3 +42,27 @@ class StatusView(APIView):
}
payload["server_time_ms"] = round((time.perf_counter() - started) * 1000, 1)
return Response(payload)
class StatsView(APIView):
"""Staff-only runtime statistics for the dashboard."""
permission_classes = [IsAuthenticated]
def get(self, request):
user = request.user
if not (
user.is_staff or user.is_superuser or user.role == user.ROLE_STAFF
):
raise PermissionDenied("Staff only.")
from apps.library.tools import storage_info
return Response(
{
"system": stats.system_stats(),
"gpus": stats.gpu_stats(),
"disk": storage_info(),
"jobs": stats.jobs_stats(),
"log": stats.log_tail(),
}
)