Documentation
¶
Overview ¶
Package alerts provides configurable alert management for TokMan. Supports token limits, usage spikes, cost thresholds, and custom alerts.
Index ¶
- type Alert
- type AlertSeverity
- type AlertType
- type Config
- type Manager
- func (m *Manager) Acknowledge(id string) error
- func (m *Manager) CheckCostThreshold(dailyCost, weeklyCost float64) []Alert
- func (m *Manager) CheckEfficiency(efficiencyPct float64) []Alert
- func (m *Manager) CheckParseFailureRate(failureRate float64) []Alert
- func (m *Manager) CheckTokenLimit(saved24h, savedTotal int64) []Alert
- func (m *Manager) CheckUsageSpike(currentAvg, baselineAvg float64) []Alert
- func (m *Manager) ClearResolved() int
- func (m *Manager) GetActive() []Alert
- func (m *Manager) GetActiveLocked() []Alert
- func (m *Manager) GetAll(limit int) []Alert
- func (m *Manager) GetConfig() Config
- func (m *Manager) Resolve(id string) error
- func (m *Manager) Stats() map[string]interface{}
- func (m *Manager) UpdateConfig(config Config)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
ID string `json:"id"`
Type AlertType `json:"type"`
Severity AlertSeverity `json:"severity"`
Title string `json:"title"`
Message string `json:"message"`
Value interface{} `json:"value,omitempty"`
Threshold interface{} `json:"threshold,omitempty"`
Timestamp time.Time `json:"timestamp"`
Acknowledged bool `json:"acknowledged"`
Resolved bool `json:"resolved"`
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Alert represents a triggered alert
type AlertSeverity ¶
type AlertSeverity string
AlertSeverity represents the severity level
const ( SeverityInfo AlertSeverity = "info" SeverityWarning AlertSeverity = "warning" SeverityCritical AlertSeverity = "critical" )
type AlertType ¶
type AlertType string
AlertType represents the type of alert
const ( AlertTypeDailyTokenLimit AlertType = "daily_token_limit" AlertTypeWeeklyTokenLimit AlertType = "weekly_token_limit" AlertTypeUsageSpike AlertType = "usage_spike" AlertTypeCostThreshold AlertType = "cost_threshold" AlertTypeEfficiencyDrop AlertType = "efficiency_drop" AlertTypeParseFailureRate AlertType = "parse_failure_rate" AlertTypeCacheHitRate AlertType = "cache_hit_rate" )
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
DailyTokenLimit int64 `json:"daily_token_limit"`
WeeklyTokenLimit int64 `json:"weekly_token_limit"`
UsageSpikeThreshold float64 `json:"usage_spike_threshold"`
CostThresholdDaily float64 `json:"cost_threshold_daily"`
CostThresholdWeekly float64 `json:"cost_threshold_weekly"`
MinEfficiencyPct float64 `json:"min_efficiency_pct"`
MaxParseFailureRate float64 `json:"max_parse_failure_rate"`
MinCacheHitRate float64 `json:"min_cache_hit_rate"`
CooldownMinutes int `json:"cooldown_minutes"`
NotificationWebhook string `json:"notification_webhook,omitempty"`
NotificationEmail string `json:"notification_email,omitempty"`
}
Config represents alert configuration
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles alert management
func (*Manager) Acknowledge ¶
Acknowledge marks an alert as acknowledged
func (*Manager) CheckCostThreshold ¶
CheckCostThreshold monitors cost thresholds
func (*Manager) CheckEfficiency ¶
CheckEfficiency monitors filtering efficiency
func (*Manager) CheckParseFailureRate ¶
CheckParseFailureRate monitors parse failure rate
func (*Manager) CheckTokenLimit ¶
CheckTokenLimit checks daily/weekly token limits
func (*Manager) CheckUsageSpike ¶
CheckUsageSpike detects unusual usage patterns
func (*Manager) ClearResolved ¶
ClearResolved removes all resolved alerts
func (*Manager) GetActiveLocked ¶
GetActiveLocked returns active alerts (caller must hold lock)
func (*Manager) UpdateConfig ¶
UpdateConfig updates the alert configuration