Files
mchat/ai-chat-service/chat-server/metrics-bus/metrics_bus.go
2026-04-03 10:29:38 +08:00

54 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package metrics_bus
import "github.com/prometheus/client_golang/prometheus"
type BusMetrics struct {
QuestionsTotalCounter prometheus.Counter
KeywordsQuestionsTotalCounter prometheus.Counter
SensitiveQuestionsTotalCounter prometheus.Counter
ErrQuestionsTotalCounter prometheus.Counter
}
const (
NAMESPACE = "ai_chat"
SUBSYSTEM = "chat_service"
)
func NewBusMetrics(registry *prometheus.Registry) *BusMetrics {
questionsTotalCounter := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: NAMESPACE,
Subsystem: SUBSYSTEM,
Name: "questions_total",
ConstLabels: map[string]string{"app": "ai_chat"},
Help: "记录用户提交问题的总数仅包含记录到DB的问题数量",
})
keywordsQuestionsTotalCounter := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: NAMESPACE,
Subsystem: SUBSYSTEM,
Name: "keywords_questions_total",
ConstLabels: map[string]string{"app": "ai_chat"},
Help: "记录用户提交的包含关键词的问题总数",
})
sensitiveQuestionsTotalCounter := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: NAMESPACE,
Subsystem: SUBSYSTEM,
Name: "sensitive_questions_total",
ConstLabels: map[string]string{"app": "ai_chat"},
Help: "记录用户提交的触发敏感词的问题总数",
})
errQuestionsTotalCounter := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: NAMESPACE,
Subsystem: SUBSYSTEM,
Name: "err_questions_total",
ConstLabels: map[string]string{"app": "ai_chat"},
Help: "记录用户提交问题时报错的总数",
})
registry.MustRegister(questionsTotalCounter, keywordsQuestionsTotalCounter, sensitiveQuestionsTotalCounter, errQuestionsTotalCounter)
return &BusMetrics{
QuestionsTotalCounter: questionsTotalCounter,
KeywordsQuestionsTotalCounter: keywordsQuestionsTotalCounter,
SensitiveQuestionsTotalCounter: sensitiveQuestionsTotalCounter,
ErrQuestionsTotalCounter: errQuestionsTotalCounter,
}
}