Documentation
¶
Overview ¶
Package dashboard provides observability dashboard functionality for Aster. It aggregates metrics, builds trace trees, and calculates costs from agent events.
Index ¶
- Variables
- func FormatCost(cost CostAmount) string
- type Aggregator
- func (a *Aggregator) GetCostBreakdown(ctx context.Context, opts CostQueryOpts) (*CostBreakdown, error)
- func (a *Aggregator) GetInsights(ctx context.Context) ([]Insight, error)
- func (a *Aggregator) GetOverviewStats(ctx context.Context, period string) (*OverviewStats, error)
- func (a *Aggregator) GetOverviewStatsFromEventBuses(ctx context.Context, period string, provider EventBusProvider) (*OverviewStats, error)
- func (a *Aggregator) GetPerformanceStats(ctx context.Context, period string) (*PerformanceStats, error)
- func (a *Aggregator) GetTokenUsage(ctx context.Context, opts TokenQueryOpts) (*TokenUsageStats, error)
- func (a *Aggregator) GetTraceDetail(ctx context.Context, traceID string) (*TraceDetail, error)
- func (a *Aggregator) QueryTraces(ctx context.Context, opts TraceQueryOpts) (*TraceListResult, error)
- func (a *Aggregator) SetEventBus(eb *events.EventBus)
- type CostAmount
- type CostBreakdown
- type CostCalculator
- func (cc *CostCalculator) Calculate(inputTokens, outputTokens int64, model string) CostAmount
- func (cc *CostCalculator) CalculateBatch(usages []TokenUsageWithModel) CostAmount
- func (cc *CostCalculator) CalculateDetailed(inputTokens, outputTokens int64, model string) *DetailedCost
- func (cc *CostCalculator) EstimateCost(model string, estimatedInputTokens, estimatedOutputTokens int64) CostAmount
- func (cc *CostCalculator) GetPricing(model string) ModelPricing
- func (cc *CostCalculator) ListPricing() map[string]ModelPricing
- func (cc *CostCalculator) SetCurrency(currency string)
- func (cc *CostCalculator) SetPricing(model string, pricing ModelPricing)
- type CostQueryOpts
- type CostTrendPoint
- type DetailedCost
- type EventBusProvider
- type EventStreamMessage
- type EventSubscription
- type Insight
- type InsightType
- type LatencyPercentiles
- type ModelPricing
- type OverviewStats
- type PerformanceStats
- type SessionTimeline
- type SessionTimelineEntry
- type TokenCount
- type TokenQueryOpts
- type TokenTrendPoint
- type TokenUsageStats
- type TokenUsageWithModel
- type TraceBuilder
- type TraceDetail
- type TraceListResult
- type TraceNode
- type TraceNodeType
- type TraceQueryOpts
- type TraceStatus
- type TraceSummary
Constants ¶
This section is empty.
Variables ¶
var DefaultModelPricing = map[string]ModelPricing{
"claude-3-5-sonnet-20241022": {
Model: "claude-3-5-sonnet-20241022",
InputPricePerM: 3.0,
OutputPricePerM: 15.0,
Currency: "USD",
},
"claude-3-5-haiku-20241022": {
Model: "claude-3-5-haiku-20241022",
InputPricePerM: 0.8,
OutputPricePerM: 4.0,
Currency: "USD",
},
"claude-sonnet-4-20250514": {
Model: "claude-sonnet-4-20250514",
InputPricePerM: 3.0,
OutputPricePerM: 15.0,
Currency: "USD",
},
"gpt-4o": {
Model: "gpt-4o",
InputPricePerM: 2.5,
OutputPricePerM: 10.0,
Currency: "USD",
},
"gpt-4o-mini": {
Model: "gpt-4o-mini",
InputPricePerM: 0.15,
OutputPricePerM: 0.6,
Currency: "USD",
},
"deepseek-chat": {
Model: "deepseek-chat",
InputPricePerM: 0.14,
OutputPricePerM: 0.28,
Currency: "USD",
},
}
DefaultModelPricing 默认模型定价表(美元/百万 token)
Functions ¶
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator 指标聚合器
func NewAggregatorWithEventBus ¶
func NewAggregatorWithEventBus(eb *events.EventBus, st store.Store) *Aggregator
NewAggregatorWithEventBus 创建带 EventBus 的聚合器
func (*Aggregator) GetCostBreakdown ¶
func (a *Aggregator) GetCostBreakdown(ctx context.Context, opts CostQueryOpts) (*CostBreakdown, error)
GetCostBreakdown 获取成本分解
func (*Aggregator) GetInsights ¶
func (a *Aggregator) GetInsights(ctx context.Context) ([]Insight, error)
GetInsights 获取改进建议
func (*Aggregator) GetOverviewStats ¶
func (a *Aggregator) GetOverviewStats(ctx context.Context, period string) (*OverviewStats, error)
GetOverviewStats 获取概览统计
func (*Aggregator) GetOverviewStatsFromEventBuses ¶
func (a *Aggregator) GetOverviewStatsFromEventBuses(ctx context.Context, period string, provider EventBusProvider) (*OverviewStats, error)
GetOverviewStatsFromEventBuses 从多个 EventBus 获取概览统计
func (*Aggregator) GetPerformanceStats ¶
func (a *Aggregator) GetPerformanceStats(ctx context.Context, period string) (*PerformanceStats, error)
GetPerformanceStats 获取性能统计
func (*Aggregator) GetTokenUsage ¶
func (a *Aggregator) GetTokenUsage(ctx context.Context, opts TokenQueryOpts) (*TokenUsageStats, error)
GetTokenUsage 获取 Token 使用统计
func (*Aggregator) GetTraceDetail ¶
func (a *Aggregator) GetTraceDetail(ctx context.Context, traceID string) (*TraceDetail, error)
GetTraceDetail 获取追踪详情
func (*Aggregator) QueryTraces ¶
func (a *Aggregator) QueryTraces(ctx context.Context, opts TraceQueryOpts) (*TraceListResult, error)
QueryTraces 查询追踪列表
func (*Aggregator) SetEventBus ¶
func (a *Aggregator) SetEventBus(eb *events.EventBus)
SetEventBus 设置 EventBus(用于实时事件)
type CostAmount ¶
CostAmount 成本金额
type CostBreakdown ¶
type CostBreakdown struct {
Period string `json:"period"`
Total CostAmount `json:"total"`
ByAgent map[string]CostAmount `json:"by_agent,omitempty"`
ByModel map[string]CostAmount `json:"by_model,omitempty"`
Trend []CostTrendPoint `json:"trend,omitempty"`
}
CostBreakdown 成本分解
type CostCalculator ¶
type CostCalculator struct {
// contains filtered or unexported fields
}
CostCalculator 成本计算器
func NewCostCalculator ¶
func NewCostCalculator(customPricing map[string]ModelPricing) *CostCalculator
NewCostCalculator 创建成本计算器
func (*CostCalculator) Calculate ¶
func (cc *CostCalculator) Calculate(inputTokens, outputTokens int64, model string) CostAmount
Calculate 计算成本
func (*CostCalculator) CalculateBatch ¶
func (cc *CostCalculator) CalculateBatch(usages []TokenUsageWithModel) CostAmount
CalculateBatch 批量计算成本
func (*CostCalculator) CalculateDetailed ¶
func (cc *CostCalculator) CalculateDetailed(inputTokens, outputTokens int64, model string) *DetailedCost
CalculateDetailed 计算详细成本
func (*CostCalculator) EstimateCost ¶
func (cc *CostCalculator) EstimateCost(model string, estimatedInputTokens, estimatedOutputTokens int64) CostAmount
EstimateCost 预估成本(用于预算规划)
func (*CostCalculator) GetPricing ¶
func (cc *CostCalculator) GetPricing(model string) ModelPricing
GetPricing 获取模型定价
func (*CostCalculator) ListPricing ¶
func (cc *CostCalculator) ListPricing() map[string]ModelPricing
ListPricing 列出所有定价
func (*CostCalculator) SetCurrency ¶
func (cc *CostCalculator) SetCurrency(currency string)
SetCurrency 设置货币单位
func (*CostCalculator) SetPricing ¶
func (cc *CostCalculator) SetPricing(model string, pricing ModelPricing)
SetPricing 设置模型定价
type CostQueryOpts ¶
type CostQueryOpts struct {
Period string `json:"period"`
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
AgentID string `json:"agent_id,omitempty"`
}
CostQueryOpts 成本查询选项
type CostTrendPoint ¶
type CostTrendPoint struct {
Timestamp time.Time `json:"timestamp"`
Amount float64 `json:"amount"`
}
CostTrendPoint 成本趋势数据点
type DetailedCost ¶
type DetailedCost struct {
Model string `json:"model"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
InputCost CostAmount `json:"input_cost"`
OutputCost CostAmount `json:"output_cost"`
TotalCost CostAmount `json:"total_cost"`
Pricing ModelPricing `json:"pricing"`
}
DetailedCost 详细成本
type EventBusProvider ¶
EventBusProvider 提供 EventBus 列表的接口
type EventStreamMessage ¶
type EventStreamMessage struct {
Type string `json:"type"` // "event", "heartbeat", "error"
Channel string `json:"channel,omitempty"`
Event any `json:"event,omitempty"`
Timestamp time.Time `json:"timestamp"`
Error string `json:"error,omitempty"`
}
EventStreamMessage WebSocket 事件流消息
type EventSubscription ¶
type EventSubscription struct {
Channels []string `json:"channels"` // "monitor", "progress", "control"
AgentID string `json:"agent_id,omitempty"`
EventTypes []string `json:"event_types,omitempty"`
}
EventSubscription 事件订阅配置
type Insight ¶
type Insight struct {
ID string `json:"id"`
Type InsightType `json:"type"`
Severity string `json:"severity"` // "info", "warning", "critical"
Title string `json:"title"`
Description string `json:"description"`
Suggestion string `json:"suggestion"`
Data map[string]any `json:"data,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
Insight 改进建议
type InsightType ¶
type InsightType string
InsightType 建议类型
const ( InsightTypePerformance InsightType = "performance" InsightTypeCost InsightType = "cost" InsightTypeReliability InsightType = "reliability" InsightTypeUsage InsightType = "usage" )
type LatencyPercentiles ¶
type LatencyPercentiles struct {
P50 int64 `json:"p50"`
P95 int64 `json:"p95"`
P99 int64 `json:"p99"`
Avg int64 `json:"avg"`
Max int64 `json:"max"`
}
LatencyPercentiles 延迟百分位数
type ModelPricing ¶
type ModelPricing struct {
Model string `json:"model"`
InputPricePerM float64 `json:"input_price_per_m"` // 每百万 token 价格
OutputPricePerM float64 `json:"output_price_per_m"` // 每百万 token 价格
Currency string `json:"currency"`
}
ModelPricing 模型定价
type OverviewStats ¶
type OverviewStats struct {
ActiveAgents int `json:"active_agents"`
ActiveSessions int `json:"active_sessions"`
TotalRequests int64 `json:"total_requests"`
TokenUsage TokenCount `json:"token_usage"`
Cost CostAmount `json:"cost"`
ErrorRate float64 `json:"error_rate"`
AvgLatencyMs int64 `json:"avg_latency_ms"`
Period string `json:"period"` // "24h", "7d", "30d"
UpdatedAt time.Time `json:"updated_at"`
}
OverviewStats 概览统计
type PerformanceStats ¶
type PerformanceStats struct {
Period string `json:"period"`
TTFT LatencyPercentiles `json:"ttft"` // Time to First Token
TPOT LatencyPercentiles `json:"tpot"` // Time Per Output Token
ToolLatency map[string]LatencyPercentiles `json:"tool_latency"` // 按工具
AvgLoopCount float64 `json:"avg_loop_count"` // 平均循环次数
RequestCount int64 `json:"request_count"`
ErrorCount int64 `json:"error_count"`
ErrorRate float64 `json:"error_rate"`
}
PerformanceStats 性能统计
type SessionTimeline ¶
type SessionTimeline struct {
SessionID string `json:"session_id"`
AgentID string `json:"agent_id"`
Entries []SessionTimelineEntry `json:"entries"`
StartTime time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time,omitempty"`
}
SessionTimeline 会话时间线
type SessionTimelineEntry ¶
type SessionTimelineEntry struct {
Timestamp time.Time `json:"timestamp"`
Type string `json:"type"` // "message", "tool_call", "checkpoint", "error"
Data any `json:"data"`
}
SessionTimelineEntry 会话时间线条目
type TokenCount ¶
type TokenCount struct {
Input int64 `json:"input"`
Output int64 `json:"output"`
Total int64 `json:"total"`
}
TokenCount Token 计数
type TokenQueryOpts ¶
type TokenQueryOpts struct {
Period string `json:"period"` // "hour", "day", "week", "month"
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
AgentID string `json:"agent_id,omitempty"`
Model string `json:"model,omitempty"`
}
TokenQueryOpts Token 查询选项
type TokenTrendPoint ¶
type TokenTrendPoint struct {
Timestamp time.Time `json:"timestamp"`
Input int64 `json:"input"`
Output int64 `json:"output"`
}
TokenTrendPoint Token 趋势数据点
type TokenUsageStats ¶
type TokenUsageStats struct {
Period string `json:"period"` // "hour", "day", "week", "month"
Total TokenCount `json:"total"`
ByAgent map[string]TokenCount `json:"by_agent,omitempty"`
ByModel map[string]TokenCount `json:"by_model,omitempty"`
Trend []TokenTrendPoint `json:"trend,omitempty"`
Cost CostAmount `json:"cost"`
}
TokenUsageStats Token 使用统计
type TokenUsageWithModel ¶
type TokenUsageWithModel struct {
Model string `json:"model"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
}
TokenUsageWithModel Token 使用量(带模型信息)
type TraceBuilder ¶
type TraceBuilder struct {
// contains filtered or unexported fields
}
TraceBuilder 追踪树构建器
func (*TraceBuilder) BuildFromEvents ¶
func (tb *TraceBuilder) BuildFromEvents(events []types.AgentEventEnvelope) []*TraceSummary
BuildFromEvents 从事件列表构建追踪摘要列表
func (*TraceBuilder) BuildTraceDetail ¶
func (tb *TraceBuilder) BuildTraceDetail(traceID string, allEvents []types.AgentEventEnvelope) *TraceDetail
BuildTraceDetail 构建单个追踪的详情
func (*TraceBuilder) FlattenSpans ¶
func (tb *TraceBuilder) FlattenSpans(root *TraceNode) []*TraceNode
FlattenSpans 将 Span 树展平为列表
type TraceDetail ¶
type TraceDetail struct {
TraceSummary
RootSpan *TraceNode `json:"root_span"`
TokenUsage TokenCount `json:"token_usage"`
Cost CostAmount `json:"cost"`
}
TraceDetail 追踪详情
type TraceListResult ¶
type TraceListResult struct {
Traces []*TraceSummary `json:"traces"`
Total int64 `json:"total"`
HasMore bool `json:"has_more"`
}
TraceListResult 追踪列表结果
type TraceNode ¶
type TraceNode struct {
ID string `json:"id"`
Name string `json:"name"`
Type TraceNodeType `json:"type"`
StartTime time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time,omitempty"`
DurationMs int64 `json:"duration_ms"`
Status TraceStatus `json:"status"`
Attributes map[string]any `json:"attributes,omitempty"`
Children []*TraceNode `json:"children,omitempty"`
}
TraceNode 追踪节点
type TraceNodeType ¶
type TraceNodeType string
TraceNodeType 追踪节点类型
const ( TraceNodeTypeAgent TraceNodeType = "agent" TraceNodeTypeLLM TraceNodeType = "llm" TraceNodeTypeTool TraceNodeType = "tool" TraceNodeTypeMiddleware TraceNodeType = "middleware" )
type TraceQueryOpts ¶
type TraceQueryOpts struct {
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
AgentID string `json:"agent_id,omitempty"`
Status string `json:"status,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
TraceQueryOpts 追踪查询选项
type TraceStatus ¶
type TraceStatus string
TraceStatus 追踪状态
const ( TraceStatusOK TraceStatus = "ok" TraceStatusError TraceStatus = "error" TraceStatusRunning TraceStatus = "running" )
type TraceSummary ¶
type TraceSummary struct {
ID string `json:"id"`
Name string `json:"name"`
AgentID string `json:"agent_id,omitempty"`
AgentName string `json:"agent_name,omitempty"`
StartTime time.Time `json:"start_time"`
DurationMs int64 `json:"duration_ms"`
Status TraceStatus `json:"status"`
SpanCount int `json:"span_count"`
TokenUsage TokenCount `json:"token_usage"`
ErrorMessage string `json:"error_message,omitempty"`
}
TraceSummary 追踪摘要(用于列表展示)