Documentation
¶
Index ¶
- Constants
- func FormatBytes(bytes uint64) string
- func FormatNumber(n uint64) string
- func PrintAllStats(allStats *AllStats)
- func PrintSummary(statsFile string) error
- type AllStats
- type Collector
- func (c *Collector) AttachStore(store *Store, interval time.Duration) error
- func (c *Collector) GetSnapshot() AllStats
- func (c *Collector) RecordCacheHit(domain string, size uint64)
- func (c *Collector) RecordCacheMiss(domain string)
- func (c *Collector) RecordResponse(domain string, statusCode int)
- func (c *Collector) Stop()
- func (c *Collector) UpdateCacheSize(domain string, size uint64)
- type DomainStatRow
- type Stats
- type Store
Constants ¶
const ( KB = 1024 MB = 1024 * KB GB = 1024 * MB )
const DBFileName = "stats.db"
DBFileName is the name of the SQLite database file used to persist statistics. It lives in the cache directory next to cache_index.db.
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes converts bytes to human-readable format with 1 decimal place. - < 1 MB: "X.X KB" - >= 1 MB and < 1 GB: "X.X MB" - >= 1 GB: "X.X GB"
func FormatNumber ¶
FormatNumber formats a number with thousand separators.
func PrintAllStats ¶
func PrintAllStats(allStats *AllStats)
PrintAllStats prints statistics from AllStats struct.
func PrintSummary ¶
PrintSummary reads stats from file and prints ASCII table.
Types ¶
type AllStats ¶
AllStats represents statistics for all domains.
func (*AllStats) GetOrCreateDomainStats ¶
GetOrCreateDomainStats returns stats for a domain, creating if needed.
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector collects and manages statistics. Statistics are kept in memory for fast recording and periodically persisted to a SQLite database via a Store (see store.go), instead of being written into the config file.
func (*Collector) AttachStore ¶
AttachStore attaches a persistent store and loads any previously saved statistics into memory so counters continue to accumulate across restarts. It also starts a goroutine that periodically flushes statistics to the database. Call Stop to flush and stop the goroutine.
func (*Collector) GetSnapshot ¶
GetSnapshot returns a copy of current statistics.
func (*Collector) RecordCacheHit ¶
RecordCacheHit records a cache hit and bytes saved for a domain.
func (*Collector) RecordCacheMiss ¶
RecordCacheMiss records a cache miss for a domain.
func (*Collector) RecordResponse ¶
RecordResponse records a response status code for a domain.
func (*Collector) Stop ¶
func (c *Collector) Stop()
Stop stops the periodic writer, flushes statistics to the store and closes the store.
func (*Collector) UpdateCacheSize ¶
UpdateCacheSize updates the cache size for a domain.
type DomainStatRow ¶
type DomainStatRow struct {
Domain string `json:"domain" gorm:"primaryKey;column:domain"`
CacheHits uint64 `json:"cache_hits" gorm:"column:cache_hits"`
CacheMisses uint64 `json:"cache_misses" gorm:"column:cache_misses"`
BytesSaved uint64 `json:"bytes_saved" gorm:"column:bytes_saved"`
CacheSizeBytes uint64 `json:"cache_size_bytes" gorm:"column:cache_size_bytes"`
ErrorResponses uint64 `json:"error_responses" gorm:"column:error_responses"`
LastUpdated time.Time `json:"last_updated" gorm:"column:last_updated"`
}
DomainStatRow is the persistence model for per-domain statistics.
func (DomainStatRow) TableName ¶
func (DomainStatRow) TableName() string
TableName overrides the default GORM table name.
type Stats ¶
type Stats struct {
CacheHits uint64 `json:"cache_hits"`
CacheMisses uint64 `json:"cache_misses"`
BytesSaved uint64 `json:"bytes_saved"`
CacheSizeBytes uint64 `json:"cache_size_bytes"`
ErrorResponses uint64 `json:"error_responses"`
LastUpdated time.Time `json:"last_updated"`
}
Stats represents cache statistics for a single domain or overall.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists statistics in a SQLite database via GORM.