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:
Thiên Toán
2026-02-20 15:03:18 +07:00
committed by GitHub
parent a57a8ce206
commit 806bd4ae14
3 changed files with 339 additions and 7 deletions
+26
View File
@@ -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;