// Package stats stores and returns Mailpit statistics package stats import ( "runtime" "sync" "time" "github.com/axllent/mailpit/config" "github.com/axllent/mailpit/internal/logger" "github.com/axllent/mailpit/internal/storage" "github.com/axllent/mailpit/internal/tools" ) // Stores cached version along with its expiry time and error count. // Used to minimize repeated version lookups and track consecutive errors. type versionCache struct { // github version string value string // time to expire the cache expiry time.Time // count of consecutive errors errCount int } var ( // Version cache storing the latest GitHub version vCache versionCache // StartedAt is set to the current ime when Mailpit starts startedAt time.Time // sync mutex to prevent race condition with simultaneous requests mu sync.RWMutex smtpAccepted uint64 smtpAcceptedSize uint64 smtpRejected uint64 smtpIgnored uint64 ) // AppInformation struct // swagger:model AppInformation type AppInformation struct { // Current Mailpit version Version string // Latest Mailpit version LatestVersion string // Database path Database string // Database size in bytes DatabaseSize uint64 // Total number of messages in the database Messages uint64 // Total number of messages in the database Unread uint64 // Tags and message totals per tag Tags map[string]int64 // Runtime statistics RuntimeStats struct { // Mailpit server uptime in seconds Uptime uint64 // Current memory usage in bytes Memory uint64 // Database runtime messages deleted MessagesDeleted uint64 // Accepted runtime SMTP messages SMTPAccepted uint64 // Total runtime accepted messages size in bytes SMTPAcceptedSize uint64 // Rejected runtime SMTP messages SMTPRejected uint64 // Ignored runtime SMTP messages (when using --ignore-duplicate-ids) SMTPIgnored uint64 } } // Calculates exponential backoff duration based on the error count. func getBackoff(errCount int) time.Duration { backoff := min(time.Duration(1<