stats

package
v0.12.146-go Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package stats parses JSONL usage log files and computes aggregate statistics with ASCII-formatted output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearStats

func ClearStats() error

ClearStats deletes all log files in the usage log directory.

func FormatRecentLogs

func FormatRecentLogs(days, limit int) string

FormatRecentLogs renders individual log entries as a per-request table.

func FormatStatsASCII

func FormatStatsASCII(s AggregatedStats) string

FormatStatsASCII renders aggregated stats as an ASCII box art table.

Types

type AggregatedStats

type AggregatedStats struct {
	Period              string                `json:"period"`
	TotalRequests       int                   `json:"totalRequests"`
	TotalCost           float64               `json:"totalCost"`
	TotalBaselineCost   float64               `json:"totalBaselineCost"`
	TotalSavings        float64               `json:"totalSavings"`
	SavingsPercentage   float64               `json:"savingsPercentage"`
	AvgLatencyMs        float64               `json:"avgLatencyMs"`
	AvgCostPerRequest   float64               `json:"avgCostPerRequest"`
	ByTier              map[string]TierStats  `json:"byTier"`
	ByModel             map[string]ModelStats `json:"byModel"`
	DailyBreakdown      []DayStats            `json:"dailyBreakdown"`
	EntriesWithBaseline int                   `json:"entriesWithBaseline"`
}

AggregatedStats is the top-level stats result.

func GetStats

func GetStats(days int) AggregatedStats

GetStats reads log files and returns aggregated statistics for the given number of days.

type DayStats

type DayStats struct {
	Date              string                `json:"date"`
	TotalRequests     int                   `json:"totalRequests"`
	TotalCost         float64               `json:"totalCost"`
	TotalBaselineCost float64               `json:"totalBaselineCost"`
	TotalSavings      float64               `json:"totalSavings"`
	AvgLatencyMs      float64               `json:"avgLatencyMs"`
	ByTier            map[string]TierStats  `json:"byTier"`
	ByModel           map[string]ModelStats `json:"byModel"`
}

DayStats holds one day of aggregated usage.

type ModelStats

type ModelStats struct {
	Count      int     `json:"count"`
	Cost       float64 `json:"cost"`
	Percentage float64 `json:"percentage"`
}

ModelStats holds per-model aggregate data.

type TierStats

type TierStats struct {
	Count      int     `json:"count"`
	Cost       float64 `json:"cost"`
	Percentage float64 `json:"percentage"`
}

TierStats holds per-tier aggregate data.

Jump to

Keyboard shortcuts

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