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

@@ -5,6 +5,10 @@ definitions:
type: object
github_com_ez-api_ez-api_internal_dto.APIKeyDTO:
properties:
access_token:
type: string
account_id:
type: string
api_key:
type: string
auto_ban:
@@ -13,8 +17,14 @@ definitions:
type: string
ban_until:
type: string
expires_at:
type: string
group_id:
type: integer
project_id:
type: string
refresh_token:
type: string
status:
type: string
weight:
@@ -66,12 +76,16 @@ definitions:
type: string
google_project:
type: string
headers_profile:
type: string
models:
items:
type: string
type: array
name:
type: string
static_headers:
type: string
status:
type: string
type:
@@ -79,6 +93,10 @@ definitions:
type: object
github_com_ez-api_ez-api_internal_model.APIKey:
properties:
access_token:
type: string
account_id:
type: string
api_key:
type: string
auto_ban:
@@ -91,12 +109,26 @@ definitions:
type: string
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
weight:
@@ -228,10 +260,16 @@ definitions:
type: string
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
models:
@@ -239,8 +277,16 @@ definitions:
type: string
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
@@ -317,6 +363,19 @@ definitions:
description: Valid is true if Time is not NULL
type: boolean
type: object
internal_api.APIKeyStatsSummaryResponse:
properties:
failure_rate:
type: number
failure_requests:
type: integer
success_rate:
type: number
success_requests:
type: integer
total_requests:
type: integer
type: object
internal_api.AboutResponse:
properties:
description:
@@ -393,6 +452,13 @@ definitions:
id:
type: integer
type: object
internal_api.CountStats:
properties:
active:
type: integer
total:
type: integer
type: object
internal_api.CreateMasterRequest:
properties:
global_qps:
@@ -407,6 +473,29 @@ definitions:
- group
- name
type: object
internal_api.DashboardSummaryResponse:
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:
items:
$ref: '#/definitions/internal_api.TopModelStat'
type: array
updated_at:
type: integer
type: object
internal_api.DeleteLogsRequest:
properties:
before:
@@ -430,6 +519,9 @@ definitions:
date:
description: For group_by=day
type: string
hour:
description: For group_by=hour
type: string
model:
description: For group_by=model
type: string
@@ -474,6 +566,11 @@ definitions:
tokens:
type: integer
type: object
internal_api.LatencyStats:
properties:
avg_ms:
type: number
type: object
internal_api.ListLogsResponse:
properties:
items:
@@ -590,6 +687,15 @@ definitions:
tokens_out:
type: integer
type: object
internal_api.MasterRealtimeSummaryView:
properties:
master_id:
type: integer
qps:
type: integer
rate_limited:
type: boolean
type: object
internal_api.MasterRealtimeView:
properties:
qps:
@@ -703,6 +809,17 @@ definitions:
user_agent:
type: string
type: object
internal_api.ProviderKeyStats:
properties:
active:
type: integer
auto_disabled:
type: integer
suspended:
type: integer
total:
type: integer
type: object
internal_api.ProviderUsageAgg:
properties:
provider_id:
@@ -716,6 +833,17 @@ definitions:
tokens:
type: integer
type: object
internal_api.RequestStats:
properties:
error_rate:
type: number
failed:
type: integer
success:
type: integer
total:
type: integer
type: object
internal_api.StatusResponse:
properties:
status:
@@ -728,6 +856,30 @@ definitions:
example: 0.1.0
type: string
type: object
internal_api.SystemRealtimeView:
properties:
by_master:
items:
$ref: '#/definitions/internal_api.MasterRealtimeSummaryView'
type: array
qps:
type: integer
rate_limited_count:
type: integer
rpm:
type: integer
updated_at:
type: integer
type: object
internal_api.TokenStats:
properties:
input:
type: integer
output:
type: integer
total:
type: integer
type: object
internal_api.TokenView:
properties:
allow_ips:
@@ -775,6 +927,15 @@ definitions:
used_tokens:
type: integer
type: object
internal_api.TopModelStat:
properties:
model:
type: string
requests:
type: integer
tokens:
type: integer
type: object
internal_api.UpdateAccessRequest:
properties:
default_namespace:
@@ -884,6 +1045,22 @@ definitions:
example: 1703505600
type: integer
type: object
internal_api.apiKeyStatsFlushEntry:
properties:
api_key_id:
type: integer
requests:
type: integer
success_requests:
type: integer
type: object
internal_api.apiKeyStatsFlushRequest:
properties:
keys:
items:
$ref: '#/definitions/internal_api.apiKeyStatsFlushEntry'
type: array
type: object
internal_api.refreshModelRegistryRequest:
properties:
ref:
@@ -974,7 +1151,7 @@ paths:
- Public
/admin/api-keys:
get:
description: List API keys
description: List API keys with optional filters
parameters:
- description: page (1-based)
in: query
@@ -988,6 +1165,10 @@ paths:
in: query
name: group_id
type: integer
- description: filter by status (active, suspended, auto_disabled, manual_disabled)
in: query
name: status
type: string
produces:
- application/json
responses:
@@ -1174,6 +1355,25 @@ paths:
summary: Batch api keys
tags:
- admin
/admin/apikey-stats/summary:
get:
description: Aggregate APIKey success/failure stats across all provider groups
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_api.APIKeyStatsSummaryResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/gin.H'
security:
- AdminAuth: []
summary: APIKey stats summary (admin)
tags:
- admin
/admin/bindings:
get:
description: List all configured bindings
@@ -1377,6 +1577,43 @@ paths:
summary: Batch bindings
tags:
- admin
/admin/dashboard/summary:
get:
description: Returns aggregated metrics for dashboard display including requests,
tokens, latency, masters, keys, and provider keys statistics
parameters:
- description: 'time period: today, week, month, all'
in: query
name: period
type: string
- description: unix seconds
in: query
name: since
type: integer
- description: unix seconds
in: query
name: until
type: integer
produces:
- application/json
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'
security:
- AdminAuth: []
summary: Dashboard summary
tags:
- admin
/admin/features:
get:
description: Returns all feature flags stored in Redis (meta:features)
@@ -1400,8 +1637,7 @@ paths:
consumes:
- application/json
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.
as strings.
parameters:
- description: Feature map
in: body
@@ -1589,7 +1825,7 @@ paths:
/admin/logs/stats:
get:
description: Aggregate log stats with basic filtering. Use group_by param for
grouped statistics (model/day/month). Without group_by returns LogStatsResponse;
grouped statistics (model/day/month/hour). Without group_by returns LogStatsResponse;
with group_by returns GroupedStatsResponse.
parameters:
- description: unix seconds
@@ -1600,12 +1836,13 @@ paths:
in: query
name: until
type: integer
- description: 'group by dimension: model, day, month. Returns GroupedStatsResponse
- description: 'group by dimension: model, day, month, hour. Returns GroupedStatsResponse
when specified.'
enum:
- model
- day
- month
- hour
in: query
name: group_by
type: string
@@ -2719,6 +2956,25 @@ paths:
summary: Update provider group
tags:
- admin
/admin/realtime:
get:
description: Return aggregated realtime counters across all masters
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_api.SystemRealtimeView'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/gin.H'
security:
- AdminAuth: []
summary: System-level realtime stats (admin)
tags:
- admin
/admin/stats:
get:
description: Aggregate request stats across all masters
@@ -2801,6 +3057,37 @@ paths:
summary: Get current identity
tags:
- auth
/internal/apikey-stats/flush:
post:
consumes:
- application/json
description: Internal endpoint for flushing accumulated APIKey stats from DP
to CP database
parameters:
- description: Stats to flush
in: body
name: request
required: true
schema:
$ref: '#/definitions/internal_api.apiKeyStatsFlushRequest'
produces:
- application/json
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'
summary: Flush API key stats
tags:
- internal
/internal/stats/flush:
post:
consumes: