feat: implement dashboard with authentication and event logging

- Added dashboard functionality at /status with Basic Auth using DASHBOARD_PASSWORD.
- Created server-side event logging to track catalog and university status.
- Implemented traffic metrics tracking and display on the dashboard.
- Enhanced API tests to cover new dashboard features and authentication.
- Introduced CSS and JS for dashboard styling and functionality.
- Added tests for dashboard access control and data retrieval.
This commit is contained in:
2026-10-21 00:04:33 +03:00
parent de72d003b8
commit 3ae7b38fca
15 changed files with 1216 additions and 74 deletions

View File

@@ -185,8 +185,23 @@ export function trafficStatus(now = Date.now()) {
for (const [client, n] of b.clients) hour.clients.set(client, (hour.clients.get(client) || 0) + n);
}
const busiest = [...hour.clients.entries()].sort((a, z) => z[1] - a[1]).slice(0, 3);
// Minute by minute, oldest first, empty minutes included: the dashboard's chart.
const current = Math.floor(now / 60000);
const series = Array.from({ length: WINDOW_MINUTES }, (_, i) => {
const minute = current - WINDOW_MINUTES + 1 + i;
const b = minutes.get(minute);
return {
t: new Date(minute * 60000).toISOString(),
requests: b?.requests || 0,
notModified: b?.notModified || 0,
errors: (b?.clientErrors || 0) + (b?.serverErrors || 0),
serverErrors: b?.serverErrors || 0,
slow: b?.slow || 0,
};
});
return {
since: started,
series,
lastHour: {
...summary(hour),
clients: hour.clients.size,