stats

package
v1.1.57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate struct {
	Label        string `json:"label"`
	Vendor       string `json:"vendor"`
	Protocol     string `json:"protocol"`
	Model        string `json:"model"`
	InputTokens  int    `json:"inputTokens"`
	OutputTokens int    `json:"outputTokens"`
	TotalTokens  int    `json:"totalTokens"`
	Requests     int    `json:"requests"`
}

Aggregate represents aggregated stats for a dimension.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps a SQLite connection for stats queries.

func Open

func Open(dbPath string) (*DB, error)

Open opens the stats database at the given sessions.db path. It runs schema migrations to ensure all required tables exist (e.g. when opening an old DB from a previous vibecoding version).

func OpenDefault

func OpenDefault() (*DB, error)

OpenDefault opens the default sessions.db in the user's config directory.

func (*DB) ByModel

func (s *DB) ByModel(q Query) ([]Aggregate, error)

ByModel returns stats grouped by model.

func (*DB) ByProvider

func (s *DB) ByProvider(q Query) ([]Aggregate, error)

ByProvider returns stats grouped by vendor and protocol.

func (*DB) Close

func (s *DB) Close() error

Close closes the database connection.

func (*DB) Recent

func (s *DB) Recent(page, pageSize int) (*RecentPage, error)

Recent returns a paginated list of stats entries, ordered by most recent first.

func (*DB) RecentFiltered

func (s *DB) RecentFiltered(q Query, page, pageSize int) (*RecentPage, error)

RecentFiltered returns a paginated list of stats entries matching the query, ordered by most recent first.

func (*DB) Summary

func (s *DB) Summary(q Query) (*Summary, error)

Summary returns overall summary statistics for the given query.

func (*DB) TimeSeries

func (s *DB) TimeSeries(q Query) ([]Aggregate, error)

TimeSeries returns time-bucketed stats for charting.

type Query

type Query struct {
	From     time.Time
	To       time.Time
	Vendor   string
	Protocol string
	Model    string
	GroupBy  string // "day", "2.5h", "week", "month", "provider", "model"
}

Query represents a stats query with filters.

type RecentPage

type RecentPage struct {
	Items    []StatsEntry `json:"items"`
	Total    int          `json:"total"`
	Page     int          `json:"page"`
	PageSize int          `json:"pageSize"`
}

RecentPage represents a paginated result of recent stats entries.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the HTTP server for the stats dashboard.

func NewServer

func NewServer(db *DB, addr string) *Server

NewServer creates a new stats server.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve starts the HTTP server on an existing listener.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the HTTP server.

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server.

type StatsEntry

type StatsEntry struct {
	ID           int64     `json:"id"`
	Timestamp    time.Time `json:"timestamp"`
	SessionID    string    `json:"sessionId"`
	Vendor       string    `json:"vendor"`
	Protocol     string    `json:"protocol"`
	Model        string    `json:"model"`
	InputTokens  int       `json:"inputTokens"`
	OutputTokens int       `json:"outputTokens"`
	TotalTokens  int       `json:"totalTokens"`
	DurationMs   int       `json:"durationMs"`
}

StatsEntry represents a single recorded LLM request.

type Summary

type Summary struct {
	TotalRequests int `json:"totalRequests"`
	InputTokens   int `json:"inputTokens"`
	OutputTokens  int `json:"outputTokens"`
	TotalTokens   int `json:"totalTokens"`
}

Summary represents overall statistics summary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL