Documentation
¶
Index ¶
- func GenerateMockArchives(archivePath string, monthsCount int) error
- func GenerateMockArchivesForUser(monthsCount int) error
- func GetStatsPath() (string, error)
- type APIResponse
- type ArchiveManager
- func (am *ArchiveManager) ArchiveCurrentMonth(stats *Stats) error
- func (am *ArchiveManager) CheckAndArchive(stats *Stats) error
- func (am *ArchiveManager) GetArchivePath() string
- func (am *ArchiveManager) GetArchiveSummary(month string) (*ArchiveSummary, error)
- func (am *ArchiveManager) ListArchives() ([]string, error)
- func (am *ArchiveManager) LoadArchive(month string) (*MonthlyArchive, error)
- type ArchiveSummary
- type DailyStats
- type EndpointStats
- type MonthlyArchive
- type Proxy
- type SSEEvent
- type Stats
- func (s *Stats) FlushSave() error
- func (s *Stats) GetDailyStats(date string) map[string]*DailyStats
- func (s *Stats) GetLastSaveError() error
- func (s *Stats) GetPeriodStats(startDate, endDate string) map[string]*DailyStats
- func (s *Stats) GetStats() (int, map[string]*EndpointStats)
- func (s *Stats) Load() error
- func (s *Stats) RecordError(endpointName string)
- func (s *Stats) RecordRequest(endpointName string)
- func (s *Stats) RecordTokens(endpointName string, inputTokens, outputTokens int)
- func (s *Stats) Reset()
- func (s *Stats) Save() error
- func (s *Stats) SetStatsPath(path string)
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateMockArchives ¶ added in v1.5.0
GenerateMockArchives generates mock archive data for testing
func GenerateMockArchivesForUser ¶ added in v1.5.0
GenerateMockArchivesForUser generates mock archives in the user's archive directory
func GetStatsPath ¶ added in v0.5.2
GetStatsPath returns the stats file path
Types ¶
type APIResponse ¶
type APIResponse struct {
Usage Usage `json:"usage"`
}
APIResponse represents the structure of API responses to extract usage
type ArchiveManager ¶ added in v1.5.0
type ArchiveManager struct {
// contains filtered or unexported fields
}
ArchiveManager manages monthly data archives
func NewArchiveManager ¶ added in v1.5.0
func NewArchiveManager() (*ArchiveManager, error)
NewArchiveManager creates a new archive manager
func (*ArchiveManager) ArchiveCurrentMonth ¶ added in v1.5.0
func (am *ArchiveManager) ArchiveCurrentMonth(stats *Stats) error
ArchiveCurrentMonth archives current month's data up to yesterday (T+1 mode) Unlike archiveMonth, this method does NOT remove data from stats
func (*ArchiveManager) CheckAndArchive ¶ added in v1.5.0
func (am *ArchiveManager) CheckAndArchive(stats *Stats) error
CheckAndArchive checks if there are complete months to archive and archives them Also archives current month data in T+1 mode (without removing data)
func (*ArchiveManager) GetArchivePath ¶ added in v1.5.0
func (am *ArchiveManager) GetArchivePath() string
GetArchivePath returns the archive directory path
func (*ArchiveManager) GetArchiveSummary ¶ added in v1.5.0
func (am *ArchiveManager) GetArchiveSummary(month string) (*ArchiveSummary, error)
GetArchiveSummary returns summary statistics for an archived month
func (*ArchiveManager) ListArchives ¶ added in v1.5.0
func (am *ArchiveManager) ListArchives() ([]string, error)
ListArchives returns a list of all available archive months
func (*ArchiveManager) LoadArchive ¶ added in v1.5.0
func (am *ArchiveManager) LoadArchive(month string) (*MonthlyArchive, error)
LoadArchive loads an archived month's data
type ArchiveSummary ¶ added in v1.5.0
type ArchiveSummary struct {
TotalRequests int `json:"totalRequests"`
TotalErrors int `json:"totalErrors"`
TotalInputTokens int `json:"totalInputTokens"`
TotalOutputTokens int `json:"totalOutputTokens"`
}
ArchiveSummary represents summary statistics for a month
type DailyStats ¶ added in v1.4.0
type DailyStats struct {
Date string `json:"date"` // Format: "2006-01-02"
Requests int `json:"requests"`
Errors int `json:"errors"`
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
}
DailyStats represents statistics for a single day
type EndpointStats ¶
type EndpointStats struct {
Requests int `json:"requests"` // Computed from DailyHistory
Errors int `json:"errors"` // Computed from DailyHistory
InputTokens int `json:"inputTokens"` // Computed from DailyHistory
OutputTokens int `json:"outputTokens"` // Computed from DailyHistory
LastUsed time.Time `json:"lastUsed"`
DailyHistory map[string]*DailyStats `json:"dailyHistory"` // Key: date string (source of truth)
}
EndpointStats represents statistics for a single endpoint
type MonthlyArchive ¶ added in v1.5.0
type MonthlyArchive struct {
Month string `json:"month"` // Format: "YYYY-MM"
ArchivedAt time.Time `json:"archivedAt"` // When this archive was created
Summary ArchiveSummary `json:"summary"` // Month summary statistics
Endpoints map[string]*EndpointStats `json:"endpoints"` // Endpoint statistics with daily history
}
MonthlyArchive represents archived statistics for a single month
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy represents the proxy server
func (*Proxy) GetCurrentEndpointName ¶ added in v1.1.1
GetCurrentEndpointName returns the current endpoint name (thread-safe)
func (*Proxy) SetCurrentEndpoint ¶ added in v1.1.1
SetCurrentEndpoint manually switches to a specific endpoint by name Returns error if endpoint not found or not enabled Thread-safe and won't affect ongoing requests
type Stats ¶
type Stats struct {
TotalRequests int `json:"totalRequests"` // Computed from EndpointStats
EndpointStats map[string]*EndpointStats `json:"endpointStats"`
// contains filtered or unexported fields
}
Stats represents overall proxy statistics
func (*Stats) FlushSave ¶ added in v1.5.0
FlushSave forces an immediate save, canceling any pending debounced save
func (*Stats) GetDailyStats ¶ added in v1.4.0
func (s *Stats) GetDailyStats(date string) map[string]*DailyStats
GetDailyStats returns statistics for a specific date Only returns endpoints that have data on the specified date
func (*Stats) GetLastSaveError ¶ added in v1.5.0
GetLastSaveError returns the last save error if any
func (*Stats) GetPeriodStats ¶ added in v1.4.0
func (s *Stats) GetPeriodStats(startDate, endDate string) map[string]*DailyStats
GetPeriodStats returns aggregated statistics for a time period Only returns endpoints that have data in the specified period
func (*Stats) GetStats ¶
func (s *Stats) GetStats() (int, map[string]*EndpointStats)
GetStats returns a copy of current statistics (thread-safe) Computes aggregated values from DailyHistory
func (*Stats) RecordError ¶
RecordError records an error for an endpoint
func (*Stats) RecordRequest ¶
RecordRequest records a request for an endpoint
func (*Stats) RecordTokens ¶
RecordTokens records token usage for an endpoint
func (*Stats) SetStatsPath ¶ added in v0.5.2
SetStatsPath sets the path for stats persistence