feat(api): add dashboard summary and system realtime endpoints

Add new admin API endpoints for dashboard metrics and system-wide
realtime statistics:

- Add /admin/dashboard/summary endpoint with aggregated metrics
  including requests, tokens, latency, masters, keys, and provider
  keys statistics with time period filtering
- Add /admin/realtime endpoint for system-level realtime stats
  aggregated across all masters
- Add status filter parameter to ListAPIKeys endpoint
- Add hour grouping option to log stats aggregation
- Update OpenAPI documentation with new endpoints and schemas
This commit is contained in:
zenfun
2025-12-31 13:17:23 +08:00
parent 1a2cc5b798
commit 53c18c3867
9 changed files with 1644 additions and 21 deletions

View File

@@ -45,7 +45,7 @@
"AdminAuth": []
}
],
"description": "List API keys",
"description": "List API keys with optional filters",
"produces": [
"application/json"
],
@@ -71,6 +71,12 @@
"description": "filter by group_id",
"name": "group_id",
"in": "query"
},
{
"type": "string",
"description": "filter by status (active, suspended, auto_disabled, manual_disabled)",
"name": "status",
"in": "query"
}
],
"responses": {
@@ -356,6 +362,37 @@
}
}
},
"/admin/apikey-stats/summary": {
"get": {
"security": [
{
"AdminAuth": []
}
],
"description": "Aggregate APIKey success/failure stats across all provider groups",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "APIKey stats summary (admin)",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_api.APIKeyStatsSummaryResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/gin.H"
}
}
}
}
},
"/admin/bindings": {
"get": {
"security": [
@@ -674,6 +711,63 @@
}
}
},
"/admin/dashboard/summary": {
"get": {
"security": [
{
"AdminAuth": []
}
],
"description": "Returns aggregated metrics for dashboard display including requests, tokens, latency, masters, keys, and provider keys statistics",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "Dashboard summary",
"parameters": [
{
"type": "string",
"description": "time period: today, week, month, all",
"name": "period",
"in": "query"
},
{
"type": "integer",
"description": "unix seconds",
"name": "since",
"in": "query"
},
{
"type": "integer",
"description": "unix seconds",
"name": "until",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_api.DashboardSummaryResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/gin.H"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/gin.H"
}
}
}
}
},
"/admin/features": {
"get": {
"security": [
@@ -710,7 +804,7 @@
"AdminAuth": []
}
],
"description": "Updates selected feature flags (meta:features). Values are stored as strings. Example: dp_claude_cross_upstream controls whether /v1/messages can route to OpenAI/compatible and Google-family providers.",
"description": "Updates selected feature flags (meta:features). Values are stored as strings.",
"consumes": [
"application/json"
],
@@ -1005,7 +1099,7 @@
"AdminAuth": []
}
],
"description": "Aggregate log stats with basic filtering. Use group_by param for grouped statistics (model/day/month). Without group_by returns LogStatsResponse; with group_by returns GroupedStatsResponse.",
"description": "Aggregate log stats with basic filtering. Use group_by param for grouped statistics (model/day/month/hour). Without group_by returns LogStatsResponse; with group_by returns GroupedStatsResponse.",
"produces": [
"application/json"
],
@@ -1030,10 +1124,11 @@
"enum": [
"model",
"day",
"month"
"month",
"hour"
],
"type": "string",
"description": "group by dimension: model, day, month. Returns GroupedStatsResponse when specified.",
"description": "group by dimension: model, day, month, hour. Returns GroupedStatsResponse when specified.",
"name": "group_by",
"in": "query"
}
@@ -2770,6 +2865,37 @@
}
}
},
"/admin/realtime": {
"get": {
"security": [
{
"AdminAuth": []
}
],
"description": "Return aggregated realtime counters across all masters",
"produces": [
"application/json"
],
"tags": [
"admin"
],
"summary": "System-level realtime stats (admin)",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_api.SystemRealtimeView"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/gin.H"
}
}
}
}
},
"/admin/stats": {
"get": {
"security": [
@@ -2892,6 +3018,52 @@
}
}
},
"/internal/apikey-stats/flush": {
"post": {
"description": "Internal endpoint for flushing accumulated APIKey stats from DP to CP database",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"internal"
],
"summary": "Flush API key stats",
"parameters": [
{
"description": "Stats to flush",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_api.apiKeyStatsFlushRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/gin.H"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/gin.H"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/gin.H"
}
}
}
}
},
"/internal/stats/flush": {
"post": {
"description": "Internal endpoint for flushing accumulated key usage stats from DP to CP database",
@@ -3567,6 +3739,12 @@
"github_com_ez-api_ez-api_internal_dto.APIKeyDTO": {
"type": "object",
"properties": {
"access_token": {
"type": "string"
},
"account_id": {
"type": "string"
},
"api_key": {
"type": "string"
},
@@ -3579,9 +3757,18 @@
"ban_until": {
"type": "string"
},
"expires_at": {
"type": "string"
},
"group_id": {
"type": "integer"
},
"project_id": {
"type": "string"
},
"refresh_token": {
"type": "string"
},
"status": {
"type": "string"
},
@@ -3660,6 +3847,9 @@
"google_project": {
"type": "string"
},
"headers_profile": {
"type": "string"
},
"models": {
"type": "array",
"items": {
@@ -3669,6 +3859,9 @@
"name": {
"type": "string"
},
"static_headers": {
"type": "string"
},
"status": {
"type": "string"
},
@@ -3680,6 +3873,12 @@
"github_com_ez-api_ez-api_internal_model.APIKey": {
"type": "object",
"properties": {
"access_token": {
"type": "string"
},
"account_id": {
"type": "string"
},
"api_key": {
"type": "string"
},
@@ -3698,15 +3897,36 @@
"deletedAt": {
"$ref": "#/definitions/gorm.DeletedAt"
},
"expires_at": {
"type": "string"
},
"failure_rate": {
"type": "number"
},
"failure_requests": {
"type": "integer"
},
"group_id": {
"type": "integer"
},
"id": {
"type": "integer"
},
"project_id": {
"type": "string"
},
"status": {
"type": "string"
},
"success_rate": {
"type": "number"
},
"success_requests": {
"type": "integer"
},
"total_requests": {
"type": "integer"
},
"updatedAt": {
"type": "string"
},
@@ -3905,12 +4125,21 @@
"deletedAt": {
"$ref": "#/definitions/gorm.DeletedAt"
},
"failure_rate": {
"type": "number"
},
"failure_requests": {
"type": "integer"
},
"google_location": {
"type": "string"
},
"google_project": {
"type": "string"
},
"headers_profile": {
"type": "string"
},
"id": {
"type": "integer"
},
@@ -3921,9 +4150,21 @@
"name": {
"type": "string"
},
"static_headers": {
"type": "string"
},
"status": {
"type": "string"
},
"success_rate": {
"type": "number"
},
"success_requests": {
"type": "integer"
},
"total_requests": {
"type": "integer"
},
"type": {
"description": "openai, anthropic, gemini",
"type": "string"
@@ -4040,6 +4281,26 @@
}
}
},
"internal_api.APIKeyStatsSummaryResponse": {
"type": "object",
"properties": {
"failure_rate": {
"type": "number"
},
"failure_requests": {
"type": "integer"
},
"success_rate": {
"type": "number"
},
"success_requests": {
"type": "integer"
},
"total_requests": {
"type": "integer"
}
}
},
"internal_api.AboutResponse": {
"type": "object",
"properties": {
@@ -4155,6 +4416,17 @@
}
}
},
"internal_api.CountStats": {
"type": "object",
"properties": {
"active": {
"type": "integer"
},
"total": {
"type": "integer"
}
}
},
"internal_api.CreateMasterRequest": {
"type": "object",
"required": [
@@ -4176,6 +4448,41 @@
}
}
},
"internal_api.DashboardSummaryResponse": {
"type": "object",
"properties": {
"keys": {
"$ref": "#/definitions/internal_api.CountStats"
},
"latency": {
"$ref": "#/definitions/internal_api.LatencyStats"
},
"masters": {
"$ref": "#/definitions/internal_api.CountStats"
},
"period": {
"type": "string"
},
"provider_keys": {
"$ref": "#/definitions/internal_api.ProviderKeyStats"
},
"requests": {
"$ref": "#/definitions/internal_api.RequestStats"
},
"tokens": {
"$ref": "#/definitions/internal_api.TokenStats"
},
"top_models": {
"type": "array",
"items": {
"$ref": "#/definitions/internal_api.TopModelStat"
}
},
"updated_at": {
"type": "integer"
}
}
},
"internal_api.DeleteLogsRequest": {
"type": "object",
"properties": {
@@ -4211,6 +4518,10 @@
"description": "For group_by=day",
"type": "string"
},
"hour": {
"description": "For group_by=hour",
"type": "string"
},
"model": {
"description": "For group_by=model",
"type": "string"
@@ -4278,6 +4589,14 @@
}
}
},
"internal_api.LatencyStats": {
"type": "object",
"properties": {
"avg_ms": {
"type": "number"
}
}
},
"internal_api.ListLogsResponse": {
"type": "object",
"properties": {
@@ -4454,6 +4773,20 @@
}
}
},
"internal_api.MasterRealtimeSummaryView": {
"type": "object",
"properties": {
"master_id": {
"type": "integer"
},
"qps": {
"type": "integer"
},
"rate_limited": {
"type": "boolean"
}
}
},
"internal_api.MasterRealtimeView": {
"type": "object",
"properties": {
@@ -4627,6 +4960,23 @@
}
}
},
"internal_api.ProviderKeyStats": {
"type": "object",
"properties": {
"active": {
"type": "integer"
},
"auto_disabled": {
"type": "integer"
},
"suspended": {
"type": "integer"
},
"total": {
"type": "integer"
}
}
},
"internal_api.ProviderUsageAgg": {
"type": "object",
"properties": {
@@ -4647,6 +4997,23 @@
}
}
},
"internal_api.RequestStats": {
"type": "object",
"properties": {
"error_rate": {
"type": "number"
},
"failed": {
"type": "integer"
},
"success": {
"type": "integer"
},
"total": {
"type": "integer"
}
}
},
"internal_api.StatusResponse": {
"type": "object",
"properties": {
@@ -4664,6 +5031,43 @@
}
}
},
"internal_api.SystemRealtimeView": {
"type": "object",
"properties": {
"by_master": {
"type": "array",
"items": {
"$ref": "#/definitions/internal_api.MasterRealtimeSummaryView"
}
},
"qps": {
"type": "integer"
},
"rate_limited_count": {
"type": "integer"
},
"rpm": {
"type": "integer"
},
"updated_at": {
"type": "integer"
}
}
},
"internal_api.TokenStats": {
"type": "object",
"properties": {
"input": {
"type": "integer"
},
"output": {
"type": "integer"
},
"total": {
"type": "integer"
}
}
},
"internal_api.TokenView": {
"type": "object",
"properties": {
@@ -4735,6 +5139,20 @@
}
}
},
"internal_api.TopModelStat": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"requests": {
"type": "integer"
},
"tokens": {
"type": "integer"
}
}
},
"internal_api.UpdateAccessRequest": {
"type": "object",
"properties": {
@@ -4890,6 +5308,31 @@
}
}
},
"internal_api.apiKeyStatsFlushEntry": {
"type": "object",
"properties": {
"api_key_id": {
"type": "integer"
},
"requests": {
"type": "integer"
},
"success_requests": {
"type": "integer"
}
}
},
"internal_api.apiKeyStatsFlushRequest": {
"type": "object",
"properties": {
"keys": {
"type": "array",
"items": {
"$ref": "#/definitions/internal_api.apiKeyStatsFlushEntry"
}
}
}
},
"internal_api.refreshModelRegistryRequest": {
"type": "object",
"properties": {
@@ -4999,4 +5442,4 @@
"in": "header"
}
}
}
}