Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var EntityNames = []string{
"token", "user", "channel", "model_config", "agent", "user_group",
"model_routing", "user_routings",
}
EntityNames 是固定的实体顺序,前后端共用。
Functions ¶
func Aggregate ¶
func Aggregate(snapshots []AgentSnapshot) map[string]ClusterEntityStats
Aggregate 把多个 agent 的快照按实体维度求和。 输入空 / 全 offline 时仍返回 6 个实体的零值,前端就不必判 nil。
Types ¶
type AgentCacheSnapshot ¶
type AgentCacheSnapshot struct {
AgentID string `json:"agent_id"`
Name string `json:"name"`
Online bool `json:"online"`
LastSeen int64 `json:"last_seen"`
CacheStats map[string]protocol.CacheEntityStats `json:"cache_stats,omitempty"`
}
AgentCacheSnapshot 是单 agent 在 /api/admin/cache/stats 响应里的一项。
type AgentSnapshot ¶
type AgentSnapshot struct {
AgentID string
Online bool
CacheStats map[string]protocol.CacheEntityStats
}
AgentSnapshot 是某个 agent 的 cache 快照与在线状态。 Aggregate 的入参;Online == false 的 agent 会被跳过。
type ClusterEntityStats ¶
type ClusterEntityStats struct {
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Evictions int64 `json:"evictions"`
NegativeHits int64 `json:"negative_hits"`
Size int `json:"size"`
Capacity int `json:"capacity"`
HitRate *float64 `json:"hit_rate"`
Util *float64 `json:"util"`
}
ClusterEntityStats 是单实体跨 agent 聚合后的结果。 HitRate 与 Util 在分母为 0 时为 nil(前端渲染为 "—")。
type Handler ¶
type Handler struct {
GetOnlineAgentIDs func() []string
GetRuntime func(agentID string) *msync.AgentRuntime
}
Handler 依赖 Hub 提供 online 列表 + per-agent runtime; 用 DAO 把 agent_id → name 拼出来。
func (*Handler) Stats ¶
func (h *Handler) Stats(c *app.Context, _ api.EmptyRequest) (StatsResponse, error)
Stats 返回所有 agent 的 cache 快照 + 集群聚合。
online 仅以 Hub 的 WebSocket 连接为准(Hub.IsOnline 等价于 "这个 agent_id 在 GetOnlineAgentIDs 返回值里"),不依赖 last_seen。 offline agent 也会列在 agents[] 里(带最近 last_seen),但 不计入 cluster 聚合。
type StatsResponse ¶
type StatsResponse struct {
Agents []AgentCacheSnapshot `json:"agents"`
Cluster map[string]ClusterEntityStats `json:"cluster"`
}
StatsResponse 是 /api/admin/cache/stats 的整体响应。
Click to show internal directories.
Click to hide internal directories.