Documentation
¶
Overview ¶
Package memory provides memory tracking for worker processes
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string
func GetOrFindWorkerPID ¶
GetOrFindWorkerPID attempts to find a worker PID by searching processes This is a fallback when the worker PID is not directly known
Types ¶
type Stats ¶
type Stats struct {
TotalWorkers int `json:"total_workers"`
TotalRSSBytes int64 `json:"total_rss_bytes"`
AvgRSSBytes int64 `json:"avg_rss_bytes"`
PeakRSSBytes int64 `json:"peak_rss_bytes"`
LastUpdated time.Time `json:"last_updated"`
SystemTotalMB int64 `json:"system_total_mb"`
SystemAvailableMB int64 `json:"system_available_mb"`
SystemUsedPercent float64 `json:"system_used_percent"`
}
Stats aggregates memory statistics across all tracked workers
type SystemMemory ¶
type SystemMemory struct {
TotalMB int64 `json:"total_mb"`
AvailableMB int64 `json:"available_mb"`
UsedPercent float64 `json:"used_percent"`
}
SystemMemory represents system-wide memory information
func GetSystemMemory ¶
func GetSystemMemory() (*SystemMemory, error)
GetSystemMemory retrieves system-wide memory information from /proc/meminfo.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker tracks memory usage of worker processes
func (*Tracker) GetWorkerMemory ¶
func (t *Tracker) GetWorkerMemory(pid int) (*WorkerMemory, bool)
GetWorkerMemory returns memory info for a specific worker
func (*Tracker) ShouldThrottle ¶
ShouldThrottle returns true if memory usage indicates we should throttle
type WorkerMemory ¶
type WorkerMemory struct {
PID int `json:"pid"`
RSSBytes int64 `json:"rss_bytes"` // Resident Set Size in bytes
VMSBytes int64 `json:"vms_bytes"` // Virtual Memory Size in bytes
LastUpdated time.Time `json:"last_updated"`
SampleCount int `json:"sample_count"`
PeakRSS int64 `json:"peak_rss"` // Peak RSS observed
}
WorkerMemory represents memory metrics for a worker process
func GetProcessMemory ¶
func GetProcessMemory(pid int) (*WorkerMemory, error)
GetProcessMemory retrieves memory usage for a process by PID using /proc/[pid]/statm.
func GetSelfMemory ¶
func GetSelfMemory() (*WorkerMemory, error)
GetSelfMemory returns memory usage of the current process