70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
// Package metrics 定义 Prometheus 监控指标。
|
|
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
// SearchTotal 按 provider 统计搜索请求总数。
|
|
SearchTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "bowen_search_total",
|
|
Help: "Total search requests by provider.",
|
|
},
|
|
[]string{"provider"},
|
|
)
|
|
|
|
// SearchDuration 搜索请求耗时直方图。
|
|
SearchDuration = promauto.NewHistogram(
|
|
prometheus.HistogramOpts{
|
|
Name: "bowen_search_duration_seconds",
|
|
Help: "Search request duration in seconds.",
|
|
Buckets: prometheus.DefBuckets,
|
|
},
|
|
)
|
|
|
|
// SearchErrors 按原因统计搜索错误。
|
|
SearchErrors = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "bowen_search_errors_total",
|
|
Help: "Search errors by reason.",
|
|
},
|
|
[]string{"reason"},
|
|
)
|
|
|
|
// CacheHits 缓存命中总数。
|
|
CacheHits = promauto.NewCounter(
|
|
prometheus.CounterOpts{
|
|
Name: "bowen_cache_hits_total",
|
|
Help: "Total cache hits.",
|
|
},
|
|
)
|
|
|
|
// CacheMisses 缓存未命中总数。
|
|
CacheMisses = promauto.NewCounter(
|
|
prometheus.CounterOpts{
|
|
Name: "bowen_cache_misses_total",
|
|
Help: "Total cache misses.",
|
|
},
|
|
)
|
|
|
|
// CacheHitsL2 Redis 二级缓存命中数。
|
|
CacheHitsL2 = promauto.NewCounter(
|
|
prometheus.CounterOpts{
|
|
Name: "bowen_cache_hits_l2_total",
|
|
Help: "L2 (Redis) cache hits.",
|
|
},
|
|
)
|
|
|
|
// ActiveKeys 各 provider 的活跃密钥数。
|
|
ActiveKeys = promauto.NewGaugeVec(
|
|
prometheus.GaugeOpts{
|
|
Name: "bowen_active_keys",
|
|
Help: "Number of active API keys by provider.",
|
|
},
|
|
[]string{"provider"},
|
|
)
|
|
)
|