feat(network): Add traffic stats endpoint and dashboard UI; enhance platform services and certificate health reporting
This commit is contained in:
@@ -317,6 +317,8 @@ export class OneboxHttpServer {
|
||||
return await this.handleGetNetworkTargetsRequest();
|
||||
} else if (path === '/api/network/stats' && method === 'GET') {
|
||||
return await this.handleGetNetworkStatsRequest();
|
||||
} else if (path === '/api/network/traffic-stats' && method === 'GET') {
|
||||
return await this.handleGetTrafficStatsRequest(new URL(req.url));
|
||||
} else {
|
||||
return this.jsonResponse({ success: false, error: 'Not found' }, 404);
|
||||
}
|
||||
@@ -1365,6 +1367,37 @@ export class OneboxHttpServer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get traffic stats from Caddy access logs
|
||||
*/
|
||||
private async handleGetTrafficStatsRequest(url: URL): Promise<Response> {
|
||||
try {
|
||||
// Get minutes parameter (default: 60)
|
||||
const minutesParam = url.searchParams.get('minutes');
|
||||
const minutes = minutesParam ? parseInt(minutesParam, 10) : 60;
|
||||
|
||||
if (isNaN(minutes) || minutes < 1 || minutes > 60) {
|
||||
return this.jsonResponse({
|
||||
success: false,
|
||||
error: 'Invalid minutes parameter. Must be between 1 and 60.',
|
||||
}, 400);
|
||||
}
|
||||
|
||||
const trafficStats = this.oneboxRef.caddyLogReceiver.getTrafficStats(minutes);
|
||||
|
||||
return this.jsonResponse({
|
||||
success: true,
|
||||
data: trafficStats,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(`Failed to get traffic stats: ${getErrorMessage(error)}`);
|
||||
return this.jsonResponse({
|
||||
success: false,
|
||||
error: getErrorMessage(error) || 'Failed to get traffic stats',
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast message to all connected WebSocket clients
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user