Documentation
¶
Overview ¶
包 metrics 提供基于 Prometheus 的全链路指标采集能力,覆盖 HTTP、LLM、Agent、缓存与数据库五大维度。
概述 ¶
本包通过 Collector 统一注册和记录 Prometheus 指标,使用 promauto 自动注册机制,避免手动管理 Registry。所有指标按 namespace 隔离, 支持多维度 label 分组,便于 Grafana 等工具进行可视化与告警。
核心类型 ¶
- Collector:指标收集器,持有 Counter、Histogram、Gauge 等 Prometheus 向量指标,按业务域分组管理。
主要能力 ¶
- HTTP 指标:请求总数、请求耗时、请求/响应体大小, 按 method/path/status 分组,状态码归类为 2xx/3xx/4xx/5xx。
- LLM 指标:请求总数、请求耗时、Token 用量(prompt/completion)、 调用成本,按 provider/model 分组。
- Agent 指标:执行总数、执行耗时、状态转换计数, 按 agent_id/agent_type 分组。
- 缓存指标:命中与未命中计数,按 cache_type 分组。
- 数据库指标:活跃/空闲连接数 Gauge、查询耗时 Histogram, 按 database/operation 分组。
Index ¶
- type Collector
- func (c *Collector) RecordAgentExecution(agentType, status string, duration time.Duration)
- func (c *Collector) RecordAgentInfo(agentID, agentType string)
- func (c *Collector) RecordAgentStateTransition(agentType, fromState, toState string)
- func (c *Collector) RecordCacheEviction(cacheType string)
- func (c *Collector) RecordCacheHit(cacheType string)
- func (c *Collector) RecordCacheMiss(cacheType string)
- func (c *Collector) RecordCacheSize(cacheType string, size int)
- func (c *Collector) RecordDBConnections(database string, open, idle int)
- func (c *Collector) RecordDBQuery(database, operation string, duration time.Duration)
- func (c *Collector) RecordHTTPRequest(method, path string, status int, duration time.Duration, ...)
- func (c *Collector) RecordLLMRequest(provider, model, status string, duration time.Duration, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector 指标收集器
func NewCollector ¶
NewCollector 创建指标收集器
func (*Collector) RecordAgentExecution ¶
RecordAgentExecution 记录 Agent 执行 K3 FIX: 移除 agentID 参数,仅使用 agentType(有限枚举值)
func (*Collector) RecordAgentInfo ¶
RecordAgentInfo 记录 agent_id 到 agent_type 的映射关系(低频调用,仅用于调试)
func (*Collector) RecordAgentStateTransition ¶
RecordAgentStateTransition 记录 Agent 状态转换 K3 FIX: 使用 agentType 替代 agentID,避免 agent_id x from_state x to_state 笛卡尔积爆炸
func (*Collector) RecordCacheEviction ¶
RecordCacheEviction 记录缓存驱逐
func (*Collector) RecordCacheHit ¶
RecordCacheHit 记录缓存命中
func (*Collector) RecordCacheMiss ¶
RecordCacheMiss 记录缓存未命中
func (*Collector) RecordCacheSize ¶
RecordCacheSize 记录缓存当前大小
func (*Collector) RecordDBConnections ¶
RecordDBConnections 记录数据库连接数
func (*Collector) RecordDBQuery ¶
RecordDBQuery 记录数据库查询