budgetalerts

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package budgetalerts provides budget alerting capabilities for TokMan

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregationType

type AggregationType string

AggregationType defines how to aggregate metrics

const (
	AggAvg   AggregationType = "avg"
	AggSum   AggregationType = "sum"
	AggMin   AggregationType = "min"
	AggMax   AggregationType = "max"
	AggCount AggregationType = "count"
	AggLast  AggregationType = "last"
)

type Alert

type Alert struct {
	ID          string
	RuleID      string
	Name        string
	Description string
	Status      AlertStatus
	Severity    Severity
	TriggeredAt time.Time
	ResolvedAt  *time.Time
	Value       float64
	Threshold   float64
	Message     string
	Metadata    map[string]string
}

Alert represents a budget alert instance

type AlertEvent

type AlertEvent struct {
	Timestamp time.Time
	AlertID   string
	RuleID    string
	Type      EventType
	Message   string
}

AlertEvent represents an alert event in history

type AlertStatus

type AlertStatus string

AlertStatus represents alert status

const (
	AlertStatusActive       AlertStatus = "active"
	AlertStatusResolved     AlertStatus = "resolved"
	AlertStatusAcknowledged AlertStatus = "acknowledged"
	AlertStatusMuted        AlertStatus = "muted"
)

type ChannelType

type ChannelType string

ChannelType defines notification channel types

const (
	ChannelEmail     ChannelType = "email"
	ChannelSlack     ChannelType = "slack"
	ChannelWebhook   ChannelType = "webhook"
	ChannelPagerDuty ChannelType = "pagerduty"
	ChannelConsole   ChannelType = "console"
)

type Condition

type Condition struct {
	Metric      string
	Operator    Operator
	Value       float64
	Duration    time.Duration
	Aggregation AggregationType
}

Condition defines when to trigger an alert

type EventType

type EventType string

EventType represents the type of event

const (
	EventTriggered    EventType = "triggered"
	EventResolved     EventType = "resolved"
	EventAcknowledged EventType = "acknowledged"
	EventEscalated    EventType = "escalated"
)

type Manager

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

Manager manages budget alerts

func NewManager

func NewManager() *Manager

NewManager creates a budget alert manager

func (*Manager) AcknowledgeAlert

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

AcknowledgeAlert acknowledges an alert

func (*Manager) CreateRule

func (m *Manager) CreateRule(config RuleConfig) (*Rule, error)

CreateRule creates a new alert rule

func (*Manager) DeleteRule

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

DeleteRule deletes a rule

func (*Manager) EvaluateRules

func (m *Manager) EvaluateRules(ctx context.Context) error

EvaluateRules evaluates all enabled rules

func (*Manager) GetActiveAlerts

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

GetActiveAlerts returns all active alerts

func (*Manager) GetHistory

func (m *Manager) GetHistory(limit int) []AlertEvent

GetHistory returns alert history

func (*Manager) GetRule

func (m *Manager) GetRule(id string) (*Rule, error)

GetRule returns a rule by ID

func (*Manager) ListRules

func (m *Manager) ListRules() []*Rule

ListRules returns all rules

func (*Manager) RegisterChannel

func (m *Manager) RegisterChannel(channel NotificationChannel)

RegisterChannel registers a notification channel

func (*Manager) ResolveAlert

func (m *Manager) ResolveAlert(id string, reason string) error

ResolveAlert manually resolves an alert

func (*Manager) SetMetricProvider

func (m *Manager) SetMetricProvider(provider MetricProvider)

SetMetricProvider sets the metric provider for evaluation

func (*Manager) UpdateRule

func (m *Manager) UpdateRule(id string, config RuleConfig) error

UpdateRule updates an existing rule

type MetricProvider

type MetricProvider interface {
	GetMetric(name string, duration time.Duration, agg AggregationType) (float64, error)
	GetCurrentValue(name string) (float64, error)
}

MetricProvider provides metric values

type NotificationChannel

type NotificationChannel struct {
	ID     string
	Name   string
	Type   ChannelType
	Config map[string]string
}

NotificationChannel defines a notification channel

type NotificationConfig

type NotificationConfig struct {
	Channels []string
	Throttle time.Duration
	Template string
}

NotificationConfig defines how to send notifications

type Operator

type Operator string

Operator defines comparison operators

const (
	OpGreaterThan      Operator = ">"
	OpGreaterThanEqual Operator = ">="
	OpLessThan         Operator = "<"
	OpLessThanEqual    Operator = "<="
	OpEqual            Operator = "=="
	OpNotEqual         Operator = "!="
)

type Rule

type Rule struct {
	ID            string
	Name          string
	Description   string
	Enabled       bool
	Condition     Condition
	Thresholds    Thresholds
	Notifications NotificationConfig
	Cooldown      time.Duration
	AutoResolve   bool
	// contains filtered or unexported fields
}

Rule defines an alert rule

type RuleConfig

type RuleConfig struct {
	Name          string
	Description   string
	Enabled       bool
	Condition     Condition
	Thresholds    Thresholds
	Notifications NotificationConfig
	Cooldown      time.Duration
	AutoResolve   bool
}

RuleConfig holds rule configuration

type RuleEvaluator

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

RuleEvaluator evaluates alert rules

type Severity

type Severity string

Severity represents alert severity

const (
	SeverityInfo      Severity = "info"
	SeverityWarning   Severity = "warning"
	SeverityCritical  Severity = "critical"
	SeverityEmergency Severity = "emergency"
)

type Thresholds

type Thresholds struct {
	Warning   float64
	Critical  float64
	Emergency float64
}

Thresholds defines multi-level thresholds

Jump to

Keyboard shortcuts

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