Documentation
¶
Index ¶
- Constants
- func AggregateByModel(records []*Record) map[string]*ModelStats
- func AggregateByRoute(records []*Record) map[string]*RouteStats
- func DBPath() (string, error)
- func DeleteAllRecords(db *sql.DB) (int64, error)
- func FormatTokens(tokens int) string
- func FormatUsage(w io.Writer, instanceID, period string, records []*Record)
- func InitDB(path string) (*sql.DB, error)
- func InsertRecord(db dbExecutor, r *Record) error
- func ParsePeriod(period string, now time.Time) (start, end time.Time, err error)
- func PruneRecords(db *sql.DB, before time.Time) (int64, error)
- type ModelStats
- type Record
- type RouteStats
- type Summary
- type Tracker
Constants ¶
const ( DefaultBufferSize = 500 DefaultFlushTimeout = 1 * time.Second // Reduced from 3s for near-realtime monitor updates )
Variables ¶
This section is empty.
Functions ¶
func AggregateByModel ¶
func AggregateByModel(records []*Record) map[string]*ModelStats
AggregateByModel groups records by profile/provider.model.
func AggregateByRoute ¶
func AggregateByRoute(records []*Record) map[string]*RouteStats
AggregateByRoute groups records by profile/provider.route.
func DeleteAllRecords ¶
DeleteAllRecords deletes all usage records and reclaims disk space.
func FormatTokens ¶
FormatTokens formats a token count for display.
func FormatUsage ¶
FormatUsage writes formatted usage statistics to the writer.
func InsertRecord ¶
InsertRecord inserts a usage record.
func ParsePeriod ¶
ParsePeriod converts a period string to start and end times.
Types ¶
type ModelStats ¶
ModelStats represents stats for a single model.
type Record ¶
type Record struct {
ID int64
InstanceID string
Profile string // active route profile name
Provider string // provider that handled the request
Route string
Model string
Tokens int
Fallbacks int
Timestamp time.Time
}
Record represents a usage record.
type RouteStats ¶
RouteStats represents stats for a single route.
type Summary ¶
Summary represents aggregated usage summary.
func AggregateSummary ¶
AggregateSummary computes overall summary from records.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker tracks usage records in memory and flushes to database. Uses a buffered channel for lock-free submission on the hot path, with a single goroutine handling batching and SQLite writes.
func NewTracker ¶
NewTracker creates a new usage tracker.