mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
feat: add API endpoint dimension to usage statistics dashboard (#152)
- Tracks endpoints like /v1/chat/completions, /v1/messages, /v1/responses - New sortable/groupable table in usage dashboard with expandable groups - Enhanced usage database aggregation by endpoint + model + provider - Added endpoint tracking to all saveRequestUsage/saveRequestDetail calls - Maintains backward compatibility with existing data structure
This commit is contained in:
@@ -396,6 +396,7 @@ export async function getUsageStats() {
|
||||
byModel: {},
|
||||
byAccount: {},
|
||||
byApiKey: {},
|
||||
byEndpoint: {},
|
||||
last10Minutes: [],
|
||||
pending: pendingRequests,
|
||||
activeRequests: []
|
||||
@@ -587,6 +588,31 @@ export async function getUsageStats() {
|
||||
apiKeyEntry.lastUsed = entry.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
// By Endpoint (endpoint + model + provider combination)
|
||||
const endpoint = entry.endpoint || "Unknown";
|
||||
const endpointModelKey = `${endpoint}|${entry.model}|${entry.provider || 'unknown'}`;
|
||||
|
||||
if (!stats.byEndpoint[endpointModelKey]) {
|
||||
stats.byEndpoint[endpointModelKey] = {
|
||||
requests: 0,
|
||||
promptTokens: 0,
|
||||
completionTokens: 0,
|
||||
cost: 0,
|
||||
endpoint: endpoint,
|
||||
rawModel: entry.model,
|
||||
provider: entry.provider,
|
||||
lastUsed: entry.timestamp
|
||||
};
|
||||
}
|
||||
const endpointEntry = stats.byEndpoint[endpointModelKey];
|
||||
endpointEntry.requests++;
|
||||
endpointEntry.promptTokens += promptTokens;
|
||||
endpointEntry.completionTokens += completionTokens;
|
||||
endpointEntry.cost += entryCost;
|
||||
if (new Date(entry.timestamp) > new Date(endpointEntry.lastUsed)) {
|
||||
endpointEntry.lastUsed = entry.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
|
||||
Reference in New Issue
Block a user