feat(stats): add usage stats and quota reset

This commit is contained in:
zenfun
2025-12-19 21:50:28 +08:00
parent 524f8c5a4e
commit ac9f0cd0a7
9 changed files with 713 additions and 3 deletions

View File

@@ -16,6 +16,9 @@ type LogView struct {
Group string `json:"group"`
KeyID uint `json:"key_id"`
ModelName string `json:"model"`
ProviderID uint `json:"provider_id"`
ProviderType string `json:"provider_type"`
ProviderName string `json:"provider_name"`
StatusCode int `json:"status_code"`
LatencyMs int64 `json:"latency_ms"`
TokensIn int64 `json:"tokens_in"`
@@ -34,6 +37,9 @@ func toLogView(r model.LogRecord) LogView {
Group: r.Group,
KeyID: r.KeyID,
ModelName: r.ModelName,
ProviderID: r.ProviderID,
ProviderType: r.ProviderType,
ProviderName: r.ProviderName,
StatusCode: r.StatusCode,
LatencyMs: r.LatencyMs,
TokensIn: r.TokensIn,
@@ -276,7 +282,7 @@ func (h *MasterHandler) ListSelfLogs(c *gin.Context) {
c.JSON(http.StatusOK, ListLogsResponse{Total: total, Limit: limit, Offset: offset, Items: out})
}
// GetSelfStats godoc
// GetSelfLogStats godoc
// @Summary Log stats (master)
// @Description Aggregate request log stats for the authenticated master
// @Tags master
@@ -287,8 +293,8 @@ func (h *MasterHandler) ListSelfLogs(c *gin.Context) {
// @Success 200 {object} LogStatsResponse
// @Failure 401 {object} gin.H
// @Failure 500 {object} gin.H
// @Router /v1/stats [get]
func (h *MasterHandler) GetSelfStats(c *gin.Context) {
// @Router /v1/logs/stats [get]
func (h *MasterHandler) GetSelfLogStats(c *gin.Context) {
master, exists := c.Get("master")
if !exists {
c.JSON(http.StatusUnauthorized, gin.H{"error": "master key not found in context"})