Documentation
¶
Overview ¶
Package idle provides advanced idle detection and policy management
Package idle provides advanced idle detection and policy management
Index ¶
- type AWSInstanceManager
- type AWSManagerAdapter
- func (a *AWSManagerAdapter) GetInstanceID(name string) (string, error)
- func (a *AWSManagerAdapter) GetInstanceNames() ([]string, error)
- func (a *AWSManagerAdapter) HibernateInstance(name string) error
- func (a *AWSManagerAdapter) ResumeInstance(name string) error
- func (a *AWSManagerAdapter) StartInstance(name string) error
- func (a *AWSManagerAdapter) StopInstance(name string) error
- type DayOfWeek
- type MetricsCollector
- type PolicyCategory
- type PolicyManager
- func (pm *PolicyManager) ApplyTemplate(instanceID string, templateID string) error
- func (pm *PolicyManager) CreateCustomTemplate(name, description string, schedules []Schedule) (*PolicyTemplate, error)
- func (pm *PolicyManager) GetAppliedTemplates(instanceID string) ([]*PolicyTemplate, error)
- func (pm *PolicyManager) GetTemplate(id string) (*PolicyTemplate, error)
- func (pm *PolicyManager) ListTemplates() []*PolicyTemplate
- func (pm *PolicyManager) ListTemplatesByCategory(category PolicyCategory) []*PolicyTemplate
- func (pm *PolicyManager) RecommendTemplate(instanceType string, tags map[string]string) (*PolicyTemplate, error)
- func (pm *PolicyManager) RemoveTemplate(instanceID string, templateID string) error
- func (pm *PolicyManager) SetScheduler(scheduler *Scheduler)
- type PolicyTemplate
- type Schedule
- type ScheduleExecution
- type ScheduleType
- type Scheduler
- func (s *Scheduler) AddSchedule(schedule *Schedule) error
- func (s *Scheduler) AssignScheduleToInstance(scheduleID, instanceName string) error
- func (s *Scheduler) DeleteSchedule(id string) error
- func (s *Scheduler) GetInstanceSchedules(instanceName string) []*Schedule
- func (s *Scheduler) GetSchedule(id string) (*Schedule, error)
- func (s *Scheduler) ListSchedules() []*Schedule
- func (s *Scheduler) RemoveSchedule(scheduleID string) error
- func (s *Scheduler) RemoveScheduleFromInstance(scheduleID, instanceName string) error
- func (s *Scheduler) Start()
- func (s *Scheduler) Stop()
- func (s *Scheduler) UpdateSchedule(id string, updates *Schedule) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AWSInstanceManager ¶
type AWSInstanceManager interface {
HibernateInstance(name string) error
ResumeInstance(name string) error
StopInstance(name string) error
StartInstance(name string) error
GetInstanceNames() ([]string, error)
GetInstanceID(name string) (string, error) // Get AWS instance ID from instance name
}
AWSInstanceManager defines the interface for AWS instance operations needed by the scheduler
type AWSManagerAdapter ¶
type AWSManagerAdapter struct {
// contains filtered or unexported fields
}
AWSManagerAdapter adapts an AWS Manager to the AWSInstanceManager interface This allows the scheduler to work with the real AWS manager without direct dependencies
func NewAWSManagerAdapter ¶
func NewAWSManagerAdapter( hibernateFn func(string) error, resumeFn func(string) error, stopFn func(string) error, startFn func(string) error, getInstanceNamesFn func() ([]string, error), getInstanceIDFn func(string) (string, error), ) *AWSManagerAdapter
NewAWSManagerAdapter creates an adapter for an AWS manager
func (*AWSManagerAdapter) GetInstanceID ¶
func (a *AWSManagerAdapter) GetInstanceID(name string) (string, error)
func (*AWSManagerAdapter) GetInstanceNames ¶
func (a *AWSManagerAdapter) GetInstanceNames() ([]string, error)
func (*AWSManagerAdapter) HibernateInstance ¶
func (a *AWSManagerAdapter) HibernateInstance(name string) error
func (*AWSManagerAdapter) ResumeInstance ¶
func (a *AWSManagerAdapter) ResumeInstance(name string) error
func (*AWSManagerAdapter) StartInstance ¶
func (a *AWSManagerAdapter) StartInstance(name string) error
func (*AWSManagerAdapter) StopInstance ¶
func (a *AWSManagerAdapter) StopInstance(name string) error
type MetricsCollector ¶
type MetricsCollector struct{}
MetricsCollector is a stub type — CloudWatch-based idle detection has been replaced by spored's on-instance monitoring. Kept for API compatibility with NewScheduler().
func NewMetricsCollector ¶
func NewMetricsCollector(_ interface{}) *MetricsCollector
NewMetricsCollector creates a no-op metrics collector (spored handles metrics on-instance).
type PolicyCategory ¶
type PolicyCategory string
PolicyCategory categorizes policy templates
const ( CategoryAggressive PolicyCategory = "aggressive" CategoryBalanced PolicyCategory = "balanced" CategoryConservative PolicyCategory = "conservative" CategoryDevelopment PolicyCategory = "development" CategoryProduction PolicyCategory = "production" CategoryResearch PolicyCategory = "research" CategoryCustom PolicyCategory = "custom" )
type PolicyManager ¶
type PolicyManager struct {
// contains filtered or unexported fields
}
PolicyManager manages hibernation policies
func NewPolicyManager ¶
func NewPolicyManager() *PolicyManager
NewPolicyManager creates a new policy manager with default templates
func (*PolicyManager) ApplyTemplate ¶
func (pm *PolicyManager) ApplyTemplate(instanceID string, templateID string) error
ApplyTemplate applies a policy template to an instance
func (*PolicyManager) CreateCustomTemplate ¶
func (pm *PolicyManager) CreateCustomTemplate(name, description string, schedules []Schedule) (*PolicyTemplate, error)
CreateCustomTemplate creates a custom policy template
func (*PolicyManager) GetAppliedTemplates ¶
func (pm *PolicyManager) GetAppliedTemplates(instanceID string) ([]*PolicyTemplate, error)
GetAppliedTemplates returns templates applied to an instance
func (*PolicyManager) GetTemplate ¶
func (pm *PolicyManager) GetTemplate(id string) (*PolicyTemplate, error)
GetTemplate retrieves a policy template
func (*PolicyManager) ListTemplates ¶
func (pm *PolicyManager) ListTemplates() []*PolicyTemplate
ListTemplates returns all available policy templates
func (*PolicyManager) ListTemplatesByCategory ¶
func (pm *PolicyManager) ListTemplatesByCategory(category PolicyCategory) []*PolicyTemplate
ListTemplatesByCategory returns templates filtered by category
func (*PolicyManager) RecommendTemplate ¶
func (pm *PolicyManager) RecommendTemplate(instanceType string, tags map[string]string) (*PolicyTemplate, error)
RecommendTemplate recommends a policy template based on instance characteristics
func (*PolicyManager) RemoveTemplate ¶
func (pm *PolicyManager) RemoveTemplate(instanceID string, templateID string) error
RemoveTemplate removes a policy template from an instance
func (*PolicyManager) SetScheduler ¶
func (pm *PolicyManager) SetScheduler(scheduler *Scheduler)
SetScheduler sets the scheduler for automated policy execution
type PolicyTemplate ¶
type PolicyTemplate struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Category PolicyCategory `json:"category"`
Schedules []Schedule `json:"schedules"`
Tags map[string]string `json:"tags"`
// Estimated savings
EstimatedSavingsPercent float64 `json:"estimated_savings_percent"`
SuitableFor []string `json:"suitable_for"`
// Configuration
AutoApply bool `json:"auto_apply"`
Priority int `json:"priority"`
Conflicts []string `json:"conflicts"` // IDs of conflicting templates
}
PolicyTemplate represents a pre-configured hibernation policy
type Schedule ¶
type Schedule struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type ScheduleType `json:"type"`
Enabled bool `json:"enabled"`
PolicyID string `json:"policy_id,omitempty"` // Track which policy created this schedule
// Target instances
TargetInstances []string `json:"target_instances,omitempty"` // Specific instance names, empty means all
// Time-based scheduling
StartTime string `json:"start_time,omitempty"` // HH:MM format
EndTime string `json:"end_time,omitempty"` // HH:MM format
DaysOfWeek []DayOfWeek `json:"days_of_week,omitempty"`
Timezone string `json:"timezone,omitempty"`
// Idle-based scheduling
IdleMinutes int `json:"idle_minutes,omitempty"`
CPUThreshold float64 `json:"cpu_threshold,omitempty"`
MemoryThreshold float64 `json:"memory_threshold,omitempty"`
NetworkThreshold float64 `json:"network_threshold,omitempty"`
// Actions
HibernateAction string `json:"hibernate_action"` // hibernate, stop, terminate
WakeAction string `json:"wake_action"` // resume, start, none
// Advanced options
GracePeriodMinutes int `json:"grace_period_minutes"`
IgnoreTags []string `json:"ignore_tags"`
RequireTags []string `json:"require_tags"`
// Cost tracking
EstimatedMonthlySavings float64 `json:"estimated_monthly_savings"`
LastExecuted time.Time `json:"last_executed"`
TotalSavings float64 `json:"total_savings"`
}
Schedule represents a hibernation schedule
type ScheduleExecution ¶
type ScheduleExecution struct {
ScheduleID string
StartTime time.Time
NextRun time.Time
IsActive bool
}
ScheduleExecution tracks active schedule execution
type ScheduleType ¶
type ScheduleType string
ScheduleType defines the type of hibernation schedule
const ( ScheduleTypeDaily ScheduleType = "daily" ScheduleTypeWeekly ScheduleType = "weekly" ScheduleTypeWorkHours ScheduleType = "work_hours" ScheduleTypeCustom ScheduleType = "custom" ScheduleTypeIdle ScheduleType = "idle" )
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages hibernation schedules
func NewScheduler ¶
func NewScheduler(awsManager AWSInstanceManager, metricsCollector *MetricsCollector) *Scheduler
NewScheduler creates a new hibernation scheduler
func (*Scheduler) AddSchedule ¶
AddSchedule adds a new schedule
func (*Scheduler) AssignScheduleToInstance ¶
AssignScheduleToInstance assigns a schedule to a specific instance
func (*Scheduler) DeleteSchedule ¶
DeleteSchedule removes a schedule
func (*Scheduler) GetInstanceSchedules ¶
GetInstanceSchedules returns all schedules assigned to an instance
func (*Scheduler) GetSchedule ¶
GetSchedule retrieves a schedule
func (*Scheduler) ListSchedules ¶
ListSchedules returns all schedules
func (*Scheduler) RemoveSchedule ¶ added in v0.7.7
RemoveSchedule removes a schedule and cleans up all instance associations (Issue #288)
func (*Scheduler) RemoveScheduleFromInstance ¶
RemoveScheduleFromInstance removes a schedule from a specific instance