stats

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stats stores derived request statistics in minute buckets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartFeed

func StartFeed(ctx context.Context, s *Store, src bifrost.LogSource, tail *bifrost.Tail, pace time.Duration, rawDays int, log *slog.Logger) func()

StartFeed subscribes before the tail starts. Cancel ctx before waiting for the feed to finish.

Types

type Cursor

type Cursor struct {
	Timestamp time.Time
	ID        string
}

Cursor is the last point committed by a log feed. The zero value means it has not started.

type Dimensions

type Dimensions struct {
	Provider, Model                            string
	VirtualKeyID, RoutingRuleID, SelectedKeyID string
	FallbackIndex                              int
}

Dimensions are the untranslated request-log dimensions. Unset IDs are empty.

type ModelPair

type ModelPair struct{ Provider, Model string }

ModelPair identifies an untranslated provider and model.

type Point

type Point struct {
	Time time.Time
	Summary
}

Point is one UTC series bucket. Unlike Summary, its Errors exclude cancelled attempts and its CostUSD only includes positive charges, like the log histograms.

type Result

type Result struct {
	Summary Summary
	Series  []Point
	Groups  []Summary
}

Result contains the totals, the zero-filled series, and one summary per group predicate in input order.

type Store

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

Store holds the derived rollup, with a single SQLite connection serializing writes.

func Open

func Open(ctx context.Context, path string) (*Store, error)

Open opens the dedicated stats database at path. An existing database with a different schema version is discarded, so only one Store may own this path.

func (*Store) Close

func (s *Store) Close() error

Close closes the SQLite connection.

func (*Store) Cursor

func (s *Store) Cursor(ctx context.Context, name string) (Cursor, error)

Cursor returns the named feed's persisted position, or the zero value if absent.

func (*Store) Ingest

func (s *Store) Ingest(ctx context.Context, rows []bifrost.Log) error

Ingest records terminal attempts once within the replay window. In-flight rows stay eligible when they are delivered again as terminal attempts.

func (*Store) IngestPage

func (s *Store) IngestPage(ctx context.Context, rows []bifrost.Log, name string, pos Cursor) error

IngestPage records a page and advances the named cursor in one transaction. On restart, resume strictly after pos using timestamp and ID to break ties.

func (*Store) ModelPairs

func (s *Store) ModelPairs(ctx context.Context, from, to time.Time, filter func(Dimensions) bool) ([]ModelPair, error)

ModelPairs returns distinct nonempty models that match the range and filter, busiest first, breaking ties by model and then provider as in the log rankings. The predicate has the same restrictions as in Query.

func (*Store) Prune

func (s *Store) Prune(ctx context.Context, now time.Time, rawRetentionDays int) error

Prune removes expired minute buckets and replay IDs. The feed calls it hourly with the raw log retention; stats keep at least eight days.

func (*Store) Query

func (s *Store) Query(ctx context.Context, from, to time.Time, bucketSec int64, filter func(Dimensions) bool, groups ...func(Dimensions) bool) (Result, error)

Query includes both boundary minutes; a minute cannot be split. bucketSec must be a positive multiple of 60, or zero for no series. Predicates are evaluated while reading the store and must not call it; nil matches all dimensions.

type Summary

type Summary struct {
	Requests, Errors                            int64
	PromptTokens, CompletionTokens, TotalTokens int64
	CostUSD                                     float64
	LatencyP50Ms, LatencyP95Ms                  *float64
}

Summary holds attempt totals and approximate percentiles of successful attempts.

Jump to

Keyboard shortcuts

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