monitor

package
v0.0.0-...-bd1a880 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package monitor provides utilities for monitoring Docker containers

Index

Constants

This section is empty.

Variables

View Source
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

func (m *Monitor) MonitorContainer(containerName string) error

MonitorContainer starts monitoring a specific container

func (*Monitor) MonitoredContainers

func (m *Monitor) MonitoredContainers() []string

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) Start

func (m *Monitor) Start() error

Start starts the monitor

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop stops the monitor

func (*Monitor) StopMonitoringContainer

func (m *Monitor) StopMonitoringContainer(containerNameOrID string) error

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

Jump to

Keyboard shortcuts

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