Documentation
¶
Overview ¶
internal/recovery/health_monitor.go
internal/recovery/restart_policy.go
Index ¶
- type AlertSeverity
- type AlertType
- type DiskUsage
- type HealthAlert
- type HealthCheckFunc
- type HealthMonitor
- type HealthStatus
- type ResourceUsage
- type RestartManager
- func (rm *RestartManager) GetNotifications() <-chan RestartNotification
- func (rm *RestartManager) GetStatus() map[string]RestartStatus
- func (rm *RestartManager) RecordRestart(service string, success bool)
- func (rm *RestartManager) RegisterPolicy(service string, policy *ServicePolicy)
- func (rm *RestartManager) ResetAttempts(service string)
- func (rm *RestartManager) ShouldRestart(service string, exitCode int) (bool, time.Duration)
- type RestartNotification
- type RestartPolicy
- type RestartStatus
- type ServiceMonitor
- type ServicePolicy
- type ServiceRestarter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertSeverity ¶
type AlertSeverity string
AlertSeverity represents alert severity
const ( AlertSeverityInfo AlertSeverity = "info" AlertSeverityWarning AlertSeverity = "warning" AlertSeverityCritical AlertSeverity = "critical" )
type HealthAlert ¶
type HealthAlert struct {
Service string
Type AlertType
Message string
Severity AlertSeverity
Timestamp time.Time
Action string
}
HealthAlert represents a health alert
type HealthCheckFunc ¶
HealthCheckFunc is a function that performs health check
type HealthMonitor ¶
type HealthMonitor struct {
// contains filtered or unexported fields
}
HealthMonitor monitors service health and triggers recovery
func NewHealthMonitor ¶
func NewHealthMonitor(cfg *config.Config, restartMgr *RestartManager) (*HealthMonitor, error)
NewHealthMonitor creates a new health monitor
func (*HealthMonitor) GetAlerts ¶
func (hm *HealthMonitor) GetAlerts() <-chan HealthAlert
GetAlerts returns the alerts channel
func (*HealthMonitor) GetStatus ¶
func (hm *HealthMonitor) GetStatus() map[string]HealthStatus
GetStatus returns the current health status of all services
func (*HealthMonitor) RegisterService ¶
func (hm *HealthMonitor) RegisterService(service, containerID string, checkFunc HealthCheckFunc)
RegisterService registers a service for health monitoring
func (*HealthMonitor) Start ¶
func (hm *HealthMonitor) Start(ctx context.Context)
Start starts health monitoring for all registered services
type HealthStatus ¶
type HealthStatus struct {
Healthy bool
Message string
LastCheck time.Time
ResponseTime time.Duration
ResourceUsage ResourceUsage
}
HealthStatus represents the health status of a service
type ResourceUsage ¶
type ResourceUsage struct {
CPUPercent float64
MemoryPercent float64
MemoryUsage uint64
MemoryLimit uint64
DiskUsage uint64
NetworkErrors uint64
}
ResourceUsage represents resource usage metrics
type RestartManager ¶
type RestartManager struct {
// contains filtered or unexported fields
}
RestartManager manages container restart policies
func NewRestartManager ¶
func NewRestartManager() *RestartManager
NewRestartManager creates a new restart manager
func (*RestartManager) GetNotifications ¶
func (rm *RestartManager) GetNotifications() <-chan RestartNotification
GetNotifications returns the notification channel
func (*RestartManager) GetStatus ¶
func (rm *RestartManager) GetStatus() map[string]RestartStatus
GetStatus returns restart status for all services
func (*RestartManager) RecordRestart ¶
func (rm *RestartManager) RecordRestart(service string, success bool)
RecordRestart records a restart attempt
func (*RestartManager) RegisterPolicy ¶
func (rm *RestartManager) RegisterPolicy(service string, policy *ServicePolicy)
RegisterPolicy registers a restart policy for a service
func (*RestartManager) ResetAttempts ¶
func (rm *RestartManager) ResetAttempts(service string)
ResetAttempts resets restart attempts for a service
func (*RestartManager) ShouldRestart ¶
ShouldRestart determines if a service should be restarted
type RestartNotification ¶
type RestartNotification struct {
Service string
Attempt int
Reason string
Success bool
Timestamp time.Time
}
RestartNotification represents a restart event
type RestartPolicy ¶
type RestartPolicy string
RestartPolicy defines the restart behavior
const ( RestartPolicyAlways RestartPolicy = "always" RestartPolicyOnFailure RestartPolicy = "on-failure" RestartPolicyUnlessStopped RestartPolicy = "unless-stopped" RestartPolicyNo RestartPolicy = "no" )
type RestartStatus ¶
type RestartStatus struct {
Service string
Policy RestartPolicy
Attempts int
MaxAttempts int
LastRestart time.Time
NextBackoff time.Duration
}
RestartStatus represents the restart status of a service
type ServiceMonitor ¶
type ServiceMonitor struct {
Service string
ContainerID string
HealthCheckFunc HealthCheckFunc
Interval time.Duration
Timeout time.Duration
FailureThreshold int
// contains filtered or unexported fields
}
ServiceMonitor monitors a specific service
type ServicePolicy ¶
type ServicePolicy struct {
Service string
Policy RestartPolicy
MaxAttempts int
BackoffSeconds []int // Exponential backoff intervals
OnRestart func(service string, attempt int)
}
ServicePolicy defines restart policy for a service
type ServiceRestarter ¶
type ServiceRestarter struct {
// contains filtered or unexported fields
}
ServiceRestarter handles the actual restart logic
func NewServiceRestarter ¶
func NewServiceRestarter(manager *docker.Manager, restartMgr *RestartManager) *ServiceRestarter
NewServiceRestarter creates a new service restarter
func (*ServiceRestarter) MonitorService ¶
func (sr *ServiceRestarter) MonitorService(ctx context.Context, containerID, service string)
MonitorService starts monitoring a service for restarts
func (*ServiceRestarter) StopMonitoring ¶
func (sr *ServiceRestarter) StopMonitoring(service string)
StopMonitoring stops monitoring a service