Documentation
¶
Overview ¶
Package cost provides advanced cost optimization and alerting features
Index ¶
- type Alert
- type AlertAction
- type AlertConditions
- type AlertManager
- func (am *AlertManager) AcknowledgeAlert(alertID string) error
- func (am *AlertManager) AddRule(rule *AlertRule) error
- func (am *AlertManager) CreateDefaultRules()
- func (am *AlertManager) GetActiveAlerts() []*Alert
- func (am *AlertManager) GetAlerts() []*Alert
- func (am *AlertManager) ResolveAlert(alertID string) error
- func (am *AlertManager) Start()
- func (am *AlertManager) Stop()
- func (am *AlertManager) Subscribe(subscriber AlertSubscriber)
- type AlertRule
- type AlertSeverity
- type AlertSubscriber
- type AlertType
- type BudgetTrackerAdapter
- func (bta *BudgetTrackerAdapter) GetAllProjectIDs() ([]string, error)
- func (bta *BudgetTrackerAdapter) GetProjectBudget(projectID string) (float64, error)
- func (bta *BudgetTrackerAdapter) GetProjectCostHistory(projectID string, days int) ([]float64, error)
- func (bta *BudgetTrackerAdapter) GetProjectCurrentCost(projectID string) (float64, error)
- func (bta *BudgetTrackerAdapter) GetProjectDailyCost(projectID string) (float64, error)
- type CostDataProvider
- type CostOptimizer
- func (co *CostOptimizer) AnalyzeInstance(instance *types.Instance) []*Recommendation
- func (co *CostOptimizer) AnalyzeProject(projectID string, instances []*types.Instance) []*Recommendation
- func (co *CostOptimizer) CalculateTotalSavings(recommendations []*Recommendation) float64
- func (co *CostOptimizer) GenerateOptimizationReport(projectID string, instances []*types.Instance) *OptimizationReport
- func (co *CostOptimizer) GetTopRecommendations(recommendations []*Recommendation, n int) []*Recommendation
- type OptimizationReport
- type OptimizationType
- type Recommendation
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"`
ProjectID string `json:"project_id"`
InstanceID string `json:"instance_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
Message string `json:"message"`
Details map[string]interface{} `json:"details"`
Acknowledged bool `json:"acknowledged"`
AutoResolved bool `json:"auto_resolved"`
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
Actions []AlertAction `json:"actions"`
}
Alert represents a cost alert
type AlertAction ¶
type AlertAction struct {
Type string `json:"type"` // hibernate, stop, terminate, notify
Description string `json:"description"`
Automated bool `json:"automated"` // Whether action is taken automatically
ExecutedAt *time.Time `json:"executed_at,omitempty"`
}
AlertAction represents an action that can be taken for an alert
type AlertConditions ¶
type AlertConditions struct {
// Threshold conditions
BudgetPercentage *float64 `json:"budget_percentage,omitempty"`
DailyCostThreshold *float64 `json:"daily_cost_threshold,omitempty"`
HourlyCostThreshold *float64 `json:"hourly_cost_threshold,omitempty"`
// Trend conditions
CostIncreasePercent *float64 `json:"cost_increase_percent,omitempty"`
TrendWindow string `json:"trend_window,omitempty"` // 1h, 24h, 7d, 30d
// Anomaly conditions
StandardDeviations *float64 `json:"standard_deviations,omitempty"`
BaselineWindow string `json:"baseline_window,omitempty"`
}
AlertConditions defines conditions for triggering an alert
type AlertManager ¶
type AlertManager struct {
// contains filtered or unexported fields
}
AlertManager manages cost alerts
func NewAlertManager ¶
func NewAlertManager(costDataProvider CostDataProvider) *AlertManager
NewAlertManager creates a new alert manager
func (*AlertManager) AcknowledgeAlert ¶
func (am *AlertManager) AcknowledgeAlert(alertID string) error
AcknowledgeAlert marks an alert as acknowledged
func (*AlertManager) AddRule ¶
func (am *AlertManager) AddRule(rule *AlertRule) error
AddRule adds a new alert rule
func (*AlertManager) CreateDefaultRules ¶
func (am *AlertManager) CreateDefaultRules()
CreateDefaultRules creates default alert rules
func (*AlertManager) GetActiveAlerts ¶
func (am *AlertManager) GetActiveAlerts() []*Alert
GetActiveAlerts returns unresolved alerts
func (*AlertManager) GetAlerts ¶
func (am *AlertManager) GetAlerts() []*Alert
GetAlerts returns all alerts
func (*AlertManager) ResolveAlert ¶
func (am *AlertManager) ResolveAlert(alertID string) error
ResolveAlert marks an alert as resolved
func (*AlertManager) Subscribe ¶
func (am *AlertManager) Subscribe(subscriber AlertSubscriber)
Subscribe adds an alert subscriber
type AlertRule ¶
type AlertRule struct {
ID string `json:"id"`
Name string `json:"name"`
Type AlertType `json:"type"`
Enabled bool `json:"enabled"`
ProjectID string `json:"project_id,omitempty"` // Specific project, empty means all projects
Conditions AlertConditions `json:"conditions"`
Actions []string `json:"actions"` // Actions to take when triggered
Cooldown time.Duration `json:"cooldown"` // Minimum time between alerts
LastTriggered *time.Time `json:"last_triggered,omitempty"`
}
AlertRule defines a rule for generating alerts
type AlertSeverity ¶
type AlertSeverity string
AlertSeverity defines the severity of an alert
const ( AlertSeverityInfo AlertSeverity = "info" AlertSeverityWarning AlertSeverity = "warning" AlertSeverityCritical AlertSeverity = "critical" )
type AlertSubscriber ¶
type AlertSubscriber interface {
OnAlert(alert *Alert)
}
AlertSubscriber receives alert notifications
type AlertType ¶
type AlertType string
AlertType defines the type of cost alert
const ( AlertTypeThreshold AlertType = "threshold" // Budget threshold exceeded AlertTypeAnomaly AlertType = "anomaly" // Unusual spending pattern AlertTypeProjection AlertType = "projection" // Projected to exceed budget AlertTypeTrend AlertType = "trend" // Concerning cost trend AlertTypeOptimization AlertType = "optimization" // Cost optimization opportunity )
type BudgetTrackerAdapter ¶
type BudgetTrackerAdapter struct {
// contains filtered or unexported fields
}
BudgetTrackerAdapter adapts a BudgetTracker to the CostDataProvider interface
func NewBudgetTrackerAdapter ¶
func NewBudgetTrackerAdapter( getBudgetDataFunc func(projectID string) (float64, float64, float64, []float64, error), getAllProjectsFunc func() ([]string, error), ) *BudgetTrackerAdapter
NewBudgetTrackerAdapter creates a new adapter for a budget tracker
func (*BudgetTrackerAdapter) GetAllProjectIDs ¶
func (bta *BudgetTrackerAdapter) GetAllProjectIDs() ([]string, error)
GetAllProjectIDs returns all project IDs being tracked
func (*BudgetTrackerAdapter) GetProjectBudget ¶
func (bta *BudgetTrackerAdapter) GetProjectBudget(projectID string) (float64, error)
GetProjectBudget returns the budget for a project
func (*BudgetTrackerAdapter) GetProjectCostHistory ¶
func (bta *BudgetTrackerAdapter) GetProjectCostHistory(projectID string, days int) ([]float64, error)
GetProjectCostHistory returns cost history for calculating trends/anomalies
func (*BudgetTrackerAdapter) GetProjectCurrentCost ¶
func (bta *BudgetTrackerAdapter) GetProjectCurrentCost(projectID string) (float64, error)
GetProjectCurrentCost returns the current cost for a project
func (*BudgetTrackerAdapter) GetProjectDailyCost ¶
func (bta *BudgetTrackerAdapter) GetProjectDailyCost(projectID string) (float64, error)
GetProjectDailyCost returns the daily cost for a project
type CostDataProvider ¶
type CostDataProvider interface {
// GetProjectCurrentCost returns the current cost for a project
GetProjectCurrentCost(projectID string) (float64, error)
// GetProjectBudget returns the budget for a project
GetProjectBudget(projectID string) (float64, error)
// GetProjectDailyCost returns the daily cost for a project
GetProjectDailyCost(projectID string) (float64, error)
// GetProjectCostHistory returns cost history for calculating trends/anomalies
GetProjectCostHistory(projectID string, days int) ([]float64, error)
// GetAllProjectIDs returns all project IDs being tracked
GetAllProjectIDs() ([]string, error)
}
CostDataProvider defines the interface for retrieving cost data
type CostOptimizer ¶
type CostOptimizer struct {
// contains filtered or unexported fields
}
CostOptimizer analyzes usage patterns and provides optimization recommendations
func NewCostOptimizer ¶
func NewCostOptimizer() *CostOptimizer
NewCostOptimizer creates a new cost optimizer
func (*CostOptimizer) AnalyzeInstance ¶
func (co *CostOptimizer) AnalyzeInstance(instance *types.Instance) []*Recommendation
AnalyzeInstance analyzes an instance for optimization opportunities
func (*CostOptimizer) AnalyzeProject ¶
func (co *CostOptimizer) AnalyzeProject(projectID string, instances []*types.Instance) []*Recommendation
AnalyzeProject analyzes a project for optimization opportunities
func (*CostOptimizer) CalculateTotalSavings ¶
func (co *CostOptimizer) CalculateTotalSavings(recommendations []*Recommendation) float64
CalculateTotalSavings calculates total potential savings
func (*CostOptimizer) GenerateOptimizationReport ¶
func (co *CostOptimizer) GenerateOptimizationReport(projectID string, instances []*types.Instance) *OptimizationReport
GenerateOptimizationReport generates a comprehensive optimization report
func (*CostOptimizer) GetTopRecommendations ¶
func (co *CostOptimizer) GetTopRecommendations(recommendations []*Recommendation, n int) []*Recommendation
GetTopRecommendations returns the top N recommendations
type OptimizationReport ¶
type OptimizationReport struct {
ProjectID string `json:"project_id"`
GeneratedAt time.Time `json:"generated_at"`
TotalInstances int `json:"total_instances"`
Recommendations []*Recommendation `json:"recommendations"`
TotalSavings float64 `json:"total_savings"`
TopRecommendations []*Recommendation `json:"top_recommendations"`
Summary map[string]interface{} `json:"summary"`
}
OptimizationReport represents a complete optimization analysis
type OptimizationType ¶
type OptimizationType string
OptimizationType defines the type of cost optimization
const ( OptimizationTypeRightSize OptimizationType = "right_size" OptimizationTypeSchedule OptimizationType = "schedule" OptimizationTypeSpot OptimizationType = "spot" OptimizationTypeReserved OptimizationType = "reserved" OptimizationTypeHibernation OptimizationType = "hibernation" OptimizationTypeStorage OptimizationType = "storage" OptimizationTypeArchitecture OptimizationType = "architecture" )
type Recommendation ¶
type Recommendation struct {
ID string `json:"id"`
Type OptimizationType `json:"type"`
Priority string `json:"priority"` // high, medium, low
Title string `json:"title"`
Description string `json:"description"`
EstimatedSavings float64 `json:"estimated_savings"` // Monthly savings in dollars
SavingsPercent float64 `json:"savings_percent"`
Effort string `json:"effort"` // low, medium, high
Risk string `json:"risk"` // low, medium, high
Implementation string `json:"implementation"`
InstanceID string `json:"instance_id,omitempty"`
ProjectID string `json:"project_id,omitempty"`
Metrics map[string]float64 `json:"metrics,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
Recommendation represents a cost optimization recommendation