alerts

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package alerts provides configurable alert management for TokMan. Supports token limits, usage spikes, cost thresholds, and custom alerts.

Index

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

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default alert configuration

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles alert management

func NewManager

func NewManager(config Config) *Manager

NewManager creates a new alert manager

func (*Manager) Acknowledge

func (m *Manager) Acknowledge(id string) error

Acknowledge marks an alert as acknowledged

func (*Manager) CheckCostThreshold

func (m *Manager) CheckCostThreshold(dailyCost, weeklyCost float64) []Alert

CheckCostThreshold monitors cost thresholds

func (*Manager) CheckEfficiency

func (m *Manager) CheckEfficiency(efficiencyPct float64) []Alert

CheckEfficiency monitors filtering efficiency

func (*Manager) CheckParseFailureRate

func (m *Manager) CheckParseFailureRate(failureRate float64) []Alert

CheckParseFailureRate monitors parse failure rate

func (*Manager) CheckTokenLimit

func (m *Manager) CheckTokenLimit(saved24h, savedTotal int64) []Alert

CheckTokenLimit checks daily/weekly token limits

func (*Manager) CheckUsageSpike

func (m *Manager) CheckUsageSpike(currentAvg, baselineAvg float64) []Alert

CheckUsageSpike detects unusual usage patterns

func (*Manager) ClearResolved

func (m *Manager) ClearResolved() int

ClearResolved removes all resolved alerts

func (*Manager) GetActive

func (m *Manager) GetActive() []Alert

GetActive returns all active (unacknowledged) alerts

func (*Manager) GetActiveLocked

func (m *Manager) GetActiveLocked() []Alert

GetActiveLocked returns active alerts (caller must hold lock)

func (*Manager) GetAll

func (m *Manager) GetAll(limit int) []Alert

GetAll returns all alerts

func (*Manager) GetConfig

func (m *Manager) GetConfig() Config

GetConfig returns the current configuration

func (*Manager) Resolve

func (m *Manager) Resolve(id string) error

Resolve marks an alert as resolved

func (*Manager) Stats

func (m *Manager) Stats() map[string]interface{}

Stats returns alert statistics

func (*Manager) UpdateConfig

func (m *Manager) UpdateConfig(config Config)

UpdateConfig updates the alert configuration

Jump to

Keyboard shortcuts

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