load package provides functions to retrieve system load averages and miscellaneous process statistics. These metrics are essential for monitoring system performance and resource utilization.
Key Features
Load Average
Get 1, 5, and 15-minute load averages
Process Stats
Monitor process counts and context switches
Main Functions
Avg
Retrieves the system load averages for the past 1, 5, and 15 minutes.AvgStat containing load averages
Misc
Retrieves miscellaneous host-wide process statistics.MiscStat containing process counts and context switches
Data Structures
AvgStat
Contains system load averages.Load average over the last 1 minute
Load average over the last 5 minutes
Load average over the last 15 minutes
MiscStat
Contains process-related statistics.Total number of processes currently on the system
Total number of processes created since system boot
Number of processes currently in running state
Number of processes currently blocked waiting for I/O
Total number of context switches since system boot
Understanding Load Average
Load average represents the average number of processes waiting to run or currently running on the CPU. It’s a measure of system utilization:- < 1.0 - System is underutilized
- ≈ CPU cores - System is fully utilized
- > CPU cores - System is overloaded
- Load of 2.0 = 50% utilization
- Load of 4.0 = 100% utilization
- Load of 8.0 = System is overloaded (200%)
Usage Examples
Get Load Average
Monitor System Load
Get Process Statistics
Combined Monitoring
Using Context
Platform Support
The load package is supported on:- Linux
- macOS (Darwin)
- FreeBSD
- OpenBSD
- Solaris
- AIX
- Windows (limited support)
Platform-Specific Behavior
Linux
- Load averages read from
/proc/loadavg - Process statistics from
/proc/stat - All fields fully supported
macOS/BSD
- Load averages from
sysinfosyscall - Some process statistics may have limited availability
Windows
- Limited support for load average calculation
- May use alternative metrics
Data Sources
Linux
/proc/loadavg- Load average values/proc/stat- Process and context switch statisticssysinfo()syscall - Fallback method
Other Platforms
- Platform-specific syscalls
- Kernel statistics APIs
Common Use Cases
- Performance Monitoring - Track system load trends
- Alerting - Trigger alerts when load exceeds thresholds
- Capacity Planning - Determine when to scale resources
- Process Monitoring - Track process creation and execution
- Scheduling - Optimize workload distribution
- Troubleshooting - Identify performance bottlenecks
Best Practices
Interpret load in context
Interpret load in context
Always compare load average to the number of CPU cores. A load of 4.0 means different things on 2-core vs 8-core systems.
Monitor trends
Monitor trends
Look at all three load averages (1, 5, 15 min) to understand load trends over time.
Consider blocked processes
Consider blocked processes
High numbers of blocked processes may indicate I/O bottlenecks.
Use context switches wisely
Use context switches wisely
Very high context switch rates can indicate thrashing or excessive multitasking.
See Also
- Load Average Details - Detailed documentation for load averages
- CPU Package - CPU utilization and statistics
- Process Package - Individual process monitoring