Documentation
¶
Overview ¶
Package metrics 实现 Golem 的运行时指标监控,支持工具执行、通道发送及记忆召回的可观察性统计。
Index ¶
- type ChannelStats
- type MemoryStats
- type RuntimeMetrics
- func (m *RuntimeMetrics) Close() error
- func (m *RuntimeMetrics) Flush()
- func (m *RuntimeMetrics) RecordChannelSend(success bool) (RuntimeSnapshot, error)
- func (m *RuntimeMetrics) RecordMemoryRecall(itemCount int, sourceHits map[string]int) (RuntimeSnapshot, error)
- func (m *RuntimeMetrics) RecordToolExecution(duration time.Duration, result string, runErr error) (RuntimeSnapshot, error)
- func (m *RuntimeMetrics) Snapshot() RuntimeSnapshot
- type RuntimeSnapshot
- type ToolStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelStats ¶
type ChannelStats struct {
SendAttempts int64 `json:"send_attempts"` // 发送尝试总数
SendFailures int64 `json:"send_failures"` // 发送失败总数
}
ChannelStats 跟踪出站消息通道的发送指标。
func (ChannelStats) FailureRatio ¶
func (c ChannelStats) FailureRatio() float64
FailureRatio 返回通道发送的失败率,范围为 [0, 1]。
type MemoryStats ¶ added in v0.5.0
type MemoryStats struct {
Recalls int64 `json:"recalls"` // 召回请求总数
TotalItems int64 `json:"total_items"` // 累计召回的片段总数
LastItems int64 `json:"last_items"` // 最近一次召回的片段数
EmptyRecalls int64 `json:"empty_recalls"` // 空召回(未找到相关记忆)次数
LongTermHits int64 `json:"long_term_hits"` // 命中长期记忆的次数
DiaryRecentHits int64 `json:"diary_recent_hits"` // 命中最近日记的次数
DiaryKeywordHits int64 `json:"diary_keyword_hits"` // 通过关键词命中日记的次数
}
MemoryStats 跟踪记忆召回系统的可观察性指标。
type RuntimeMetrics ¶
type RuntimeMetrics struct {
// contains filtered or unexported fields
}
RuntimeMetrics 负责在内存中记录并定期持久化运行时指标。
func NewRuntimeMetrics ¶
func NewRuntimeMetrics(workspacePath string) *RuntimeMetrics
NewRuntimeMetrics 为指定的工作区创建一个指标记录器,并启动自动持久化协程。
func (*RuntimeMetrics) Close ¶ added in v0.6.3
func (m *RuntimeMetrics) Close() error
Close 优雅地停止刷新器,并确保最后一次指标修改被持久化。
func (*RuntimeMetrics) Flush ¶ added in v0.6.3
func (m *RuntimeMetrics) Flush()
Flush 强制将当前内存中的指标快照持久化到磁盘(如果存在修改)。
func (*RuntimeMetrics) RecordChannelSend ¶
func (m *RuntimeMetrics) RecordChannelSend(success bool) (RuntimeSnapshot, error)
RecordChannelSend 记录一次出站通道发送尝试的结果。
func (*RuntimeMetrics) RecordMemoryRecall ¶ added in v0.5.0
func (m *RuntimeMetrics) RecordMemoryRecall(itemCount int, sourceHits map[string]int) (RuntimeSnapshot, error)
RecordMemoryRecall 记录一次记忆召回操作的数量和来源分布。
func (*RuntimeMetrics) RecordToolExecution ¶
func (m *RuntimeMetrics) RecordToolExecution(duration time.Duration, result string, runErr error) (RuntimeSnapshot, error)
RecordToolExecution 记录一次工具执行的耗时与结果,并更新统计指标。
func (*RuntimeMetrics) Snapshot ¶
func (m *RuntimeMetrics) Snapshot() RuntimeSnapshot
Snapshot 返回当前内存中最新的指标快照副本。
type RuntimeSnapshot ¶
type RuntimeSnapshot struct {
UpdatedAt time.Time `json:"updated_at"` // 指标最后更新时间
Tool ToolStats `json:"tool"` // 工具执行统计
Channel ChannelStats `json:"channel"` // 消息通道发送统计
Memory MemoryStats `json:"memory"` // 记忆召回统计
}
RuntimeSnapshot 包含工具、通道及记忆模块的聚合运行时指标快照。
func ReadRuntimeSnapshot ¶
func ReadRuntimeSnapshot(workspacePath string) (RuntimeSnapshot, error)
ReadRuntimeSnapshot 从磁盘文件中读取已持久化的运行时指标快照。
type ToolStats ¶
type ToolStats struct {
Total int64 `json:"total"` // 总调用次数
Errors int64 `json:"errors"` // 失败次数
Timeouts int64 `json:"timeouts"` // 超时次数
TotalLatencyMs int64 `json:"total_latency_ms"` // 累计延迟(毫秒)
MaxLatencyMs int64 `json:"max_latency_ms"` // 最大延迟(毫秒)
LastLatencyMs int64 `json:"last_latency_ms"` // 最近一次执行延迟
P95ProxyLatencyMs int64 `json:"p95_proxy_latency_ms"` // P95 近似延迟(毫秒)
}
ToolStats 跟踪工具执行的各项关键指标。
func (ToolStats) AvgLatencyMs ¶
AvgLatencyMs 返回工具执行的平均延迟(毫秒)。
func (ToolStats) ErrorRatio ¶
ErrorRatio 返回工具执行的错误率,范围为 [0, 1]。
func (ToolStats) TimeoutRatio ¶
TimeoutRatio 返回工具执行的超时率,范围为 [0, 1]。