65dc805eb5
- 前端: ESLint+Prettier配置、Tailwind v4配置、ErrorBoundary、全局AuthLoader优化、ReactQuery分层 - 后端: MinIO凭证移除、Docker统一为govai品牌、zerolog日志封装、错误码枚举、文件上传校验、单元测试(13项全通过) - 运维: 健康检查增强(PG/Redis ping)、Prometheus指标(/metrics端点)、多租户tenant包、RateLimit nil防御 - 移动: citation_prompt.txt → internal/assets/
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
// HTTP requests
|
|
HTTPRequestsTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "http_requests_total",
|
|
Help: "Total number of HTTP requests",
|
|
},
|
|
[]string{"method", "path", "status"},
|
|
)
|
|
|
|
HTTPRequestDuration = promauto.NewHistogramVec(
|
|
prometheus.HistogramOpts{
|
|
Name: "http_request_duration_seconds",
|
|
Help: "HTTP request latency in seconds",
|
|
Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
|
|
},
|
|
[]string{"method", "path"},
|
|
)
|
|
|
|
// AI / LLM tokens
|
|
LLMTokensTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "ai_tokens_total",
|
|
Help: "Total number of AI tokens consumed",
|
|
},
|
|
[]string{"model", "type"}, // type: prompt | completion
|
|
)
|
|
|
|
LLMRequestsTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "ai_requests_total",
|
|
Help: "Total number of AI/LLM API requests",
|
|
},
|
|
[]string{"model", "status"},
|
|
)
|
|
|
|
LLMRequestDuration = promauto.NewHistogramVec(
|
|
prometheus.HistogramOpts{
|
|
Name: "ai_request_duration_seconds",
|
|
Help: "AI/LLM API request latency in seconds",
|
|
Buckets: []float64{0.1, 0.5, 1, 2, 5, 10, 30, 60},
|
|
},
|
|
[]string{"model"},
|
|
)
|
|
|
|
// Chat / conversation
|
|
ConversationsTotal = promauto.NewCounter(
|
|
prometheus.CounterOpts{
|
|
Name: "conversations_total",
|
|
Help: "Total number of chat conversations created",
|
|
},
|
|
)
|
|
|
|
MessagesTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "messages_total",
|
|
Help: "Total number of chat messages",
|
|
},
|
|
[]string{"role"}, // role: user | assistant
|
|
)
|
|
|
|
// Auth
|
|
AuthFailuresTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "auth_failures_total",
|
|
Help: "Total number of authentication failures",
|
|
},
|
|
[]string{"reason"},
|
|
)
|
|
) |