Documentation
¶
Overview ¶
Package monitor provides utilities for monitoring Docker containers
Index ¶
- Variables
- type AlertHandler
- type AlertLevel
- type AlertType
- type Monitor
- func (m *Monitor) AddAlertHandler(alertType AlertType, handler AlertHandler)
- func (m *Monitor) GetCurrentStats(containerName string) (models.ContainerStats, error)
- func (m *Monitor) GetStatsHistory(containerName string) ([]models.ContainerStats, error)
- func (m *Monitor) GetThresholds() Thresholds
- func (m *Monitor) MonitorContainer(containerName string) error
- func (m *Monitor) MonitoredContainers() []string
- func (m *Monitor) SetDefaultAlertHandler(handler AlertHandler)
- func (m *Monitor) SetThresholds(thresholds Thresholds)
- func (m *Monitor) Start() error
- func (m *Monitor) Stop()
- func (m *Monitor) StopMonitoringContainer(containerNameOrID string) error
- type ResourceAlert
- type StatsOptions
- type Thresholds
Constants ¶
This section is empty.
Variables ¶
var DefaultThresholds = Thresholds{
CPUWarning: 70.0,
CPUCritical: 90.0,
MemoryWarning: 80.0,
MemoryCritical: 95.0,
DiskWarning: 1024 * 1024 * 1024 * 20,
DiskCritical: 1024 * 1024 * 1024 * 50,
NetworkRxWarning: 1024 * 1024 * 10,
NetworkRxCritical: 1024 * 1024 * 50,
NetworkTxWarning: 1024 * 1024 * 10,
NetworkTxCritical: 1024 * 1024 * 50,
PIDsWarning: 100,
PIDsCritical: 500,
}
DefaultThresholds provides default monitoring thresholds
Functions ¶
This section is empty.
Types ¶
type AlertHandler ¶
type AlertHandler func(alert ResourceAlert)
AlertHandler is a callback function for alerts
type AlertLevel ¶
type AlertLevel string
AlertLevel represents the severity of an alert
const ( // AlertInfo is informational level AlertInfo AlertLevel = "info" // AlertWarning is warning level AlertWarning AlertLevel = "warning" // AlertCritical is critical level AlertCritical AlertLevel = "critical" )
type AlertType ¶
type AlertType string
AlertType represents the type of resource alert
const ( // AlertCPU indicates CPU usage alert AlertCPU AlertType = "cpu" // AlertMemory indicates memory usage alert AlertMemory AlertType = "memory" // AlertDisk indicates disk usage alert AlertDisk AlertType = "disk" // AlertNetwork indicates network usage alert AlertNetwork AlertType = "network" // AlertPIDs indicates process count alert AlertPIDs AlertType = "pids" // AlertHealth indicates health check alert AlertHealth AlertType = "health" )
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor provides functionality for monitoring container stats
func NewMonitor ¶
func NewMonitor(client client.APIClient, options StatsOptions) *Monitor
NewMonitor creates a new container stats monitor
func (*Monitor) AddAlertHandler ¶
func (m *Monitor) AddAlertHandler(alertType AlertType, handler AlertHandler)
AddAlertHandler adds an alert handler for a specific alert type
func (*Monitor) GetCurrentStats ¶
func (m *Monitor) GetCurrentStats(containerName string) (models.ContainerStats, error)
GetCurrentStats gets the current stats for a container
func (*Monitor) GetStatsHistory ¶
func (m *Monitor) GetStatsHistory(containerName string) ([]models.ContainerStats, error)
GetStatsHistory gets the stats history for a container
func (*Monitor) GetThresholds ¶
func (m *Monitor) GetThresholds() Thresholds
GetThresholds gets the current monitoring thresholds
func (*Monitor) MonitorContainer ¶
MonitorContainer starts monitoring a specific container
func (*Monitor) MonitoredContainers ¶
MonitoredContainers returns a list of currently monitored containers
func (*Monitor) SetDefaultAlertHandler ¶
func (m *Monitor) SetDefaultAlertHandler(handler AlertHandler)
SetDefaultAlertHandler sets the default alert handler
func (*Monitor) SetThresholds ¶
func (m *Monitor) SetThresholds(thresholds Thresholds)
SetThresholds sets the monitoring thresholds
func (*Monitor) StopMonitoringContainer ¶
StopMonitoringContainer stops monitoring a specific container
type ResourceAlert ¶
type ResourceAlert struct {
ContainerID string
ContainerName string
Type AlertType
Level AlertLevel
Message string
Value float64
Threshold float64
Timestamp time.Time
}
ResourceAlert represents a resource usage alert
type StatsOptions ¶
type StatsOptions struct {
Interval time.Duration
Thresholds Thresholds
HistorySize int
Stream bool
FilterContainers []string
AlertHandlers map[AlertType][]AlertHandler
DefaultAlertHandler AlertHandler
Logger *logrus.Logger
}
StatsOptions defines options for container stats monitoring
type Thresholds ¶
type Thresholds struct {
// CPU thresholds (percentage)
CPUWarning float64
CPUCritical float64
// Memory thresholds (percentage)
MemoryWarning float64
MemoryCritical float64
// Disk thresholds (bytes) - Note: These are typically for total usage, not rate.
// Rate thresholds might need different configuration.
DiskWarning int64
DiskCritical int64
// Network thresholds (bytes per second)
NetworkRxWarning int64
NetworkRxCritical int64
NetworkTxWarning int64
NetworkTxCritical int64
// PIDs thresholds (count)
PIDsWarning uint64
PIDsCritical uint64
}
Thresholds defines resource usage thresholds for monitoring