CPU Monitoring — Monitoring Processor Performance in Linux¶
CPU Monitoring is the process of tracking processor utilization, system load, CPU wait times, process execution, and overall processor performance. High CPU utilization can lead to slow applications, increased response times, and poor system performance. By monitoring CPU usage, administrators can identify resource-intensive processes, detect bottlenecks, and optimize workloads before they impact production systems. Every Linux administrator, DevOps engineer, Cloud Architect, Platform Engineer, and Site Reliability Engineer (SRE) should understand how to monitor CPU performance in Linux.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand CPU utilization
- Interpret load average
- Monitor processor performance
- Identify CPU-intensive processes
- Analyze CPU bottlenecks
- Monitor CPU statistics
- Troubleshoot CPU performance issues
- Apply production monitoring best practices
Prerequisites¶
Complete:
- Modules 1–11
- Module 12 Lessons 1–6
Why Learn CPU Monitoring?¶
Imagine a production API server.
Without monitoring:
With monitoring:
Monitoring CPU usage helps prevent performance degradation.
What is CPU Monitoring?¶
CPU monitoring involves observing:
- CPU utilization
- System load
- CPU idle time
- User and system CPU time
- I/O wait
- Process CPU usage
- CPU bottlenecks
CPU Performance Overview¶
Linux continuously schedules processes across available CPU cores.
CPU States¶
CPU time is divided into several categories.
| State | Description |
|---|---|
User (us) | Time spent running user processes |
System (sy) | Time spent running kernel code |
Idle (id) | CPU not performing work |
I/O Wait (wa) | Waiting for storage operations |
Nice (ni) | Time spent on lower-priority processes |
IRQ (hi) | Hardware interrupt handling |
SoftIRQ (si) | Software interrupt handling |
Steal (st) | Time taken by the hypervisor (virtual machines) |
Monitor CPU with top¶
Launch:
Example:
Press:
Sort processes by CPU usage.
Monitor CPU with htop¶
Features:
- Per-core CPU graphs
- Interactive process management
- Colorized display
- Easy sorting
Check System Load¶
Use:
Example:
The three values represent the average system load over:
- 1 minute
- 5 minutes
- 15 minutes
Understanding Load Average¶
Example:
General guideline:
| CPU Cores | Healthy Load |
|---|---|
| 2 | Around 2 |
| 4 | Around 4 |
| 8 | Around 8 |
| 16 | Around 16 |
A sustained load average significantly higher than the number of CPU cores may indicate CPU contention or processes waiting for CPU time.
CPU Statistics¶
Use:
Example:
Useful CPU columns:
Detailed CPU Statistics¶
Install sysstat if necessary.
Per-core statistics.
Displays utilization for every CPU core.
CPU Usage by Process¶
Display the highest CPU consumers.
Top 10:
View CPU Information¶
Display processor details.
Example output:
Number of CPUs¶
Example:
CPU Frequency¶
Search frequency.
Real-Time CPU Monitoring¶
Refresh every second.
CPU Information from proc¶
Detailed CPU statistics.
Useful for low-level monitoring.
Common Commands¶
Monitor CPU.
System load.
CPU statistics.
Per-core monitoring.
CPU information.
Real Production Examples¶
Monitor CPU usage.
Check system load.
View per-core usage.
Find CPU-intensive processes.
Production Perspective¶
CPU monitoring is essential for:
- Kubernetes worker nodes
- Database servers
- Java applications
- API servers
- Web servers
- CI/CD servers
- Virtual machines
- Cloud infrastructure
High CPU utilization often indicates application inefficiencies, increased workload, or insufficient resources.
Hands-on Lab¶
Task 1¶
Open top.
Press:
Sort by CPU usage.
Task 2¶
Display system load.
Task 3¶
Monitor CPU statistics.
Task 4¶
Display processor information.
Task 5¶
Display the number of CPU cores.
Task 6¶
Monitor per-core utilization.
Task 7¶
Display the top CPU-consuming processes.
Task 8¶
Review /proc/stat.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
top | Real-time CPU monitoring | Performance analysis |
uptime | Display system load | Capacity planning |
vmstat | CPU statistics | Resource monitoring |
mpstat -P ALL | Per-core CPU utilization | Multi-core analysis |
lscpu | CPU hardware information | Infrastructure inventory |
ps aux --sort=-%cpu | Top CPU consumers | Process troubleshooting |
Common CPU Monitoring Mistakes¶
| Mistake | Solution |
|---|---|
| Looking only at CPU percentage | Monitor load average as well |
Ignoring I/O wait (wa) | High wait time may indicate storage bottlenecks |
| Assuming 100% CPU always indicates a problem | Verify workload characteristics first |
| Never checking per-core utilization | Monitor all CPU cores |
| Ignoring long-term CPU trends | Use historical monitoring tools |
Production Troubleshooting Scenario¶
Scenario
Users report that an API service is responding slowly.
Investigation:
Result:
Next:
The Java application is consuming nearly all available CPU resources.
Further investigation reveals an inefficient query causing excessive processing.
After optimizing the application:
Best Practices¶
- Monitor CPU utilization continuously.
- Track system load average.
- Monitor per-core CPU usage.
- Investigate sustained high CPU utilization.
- Monitor I/O wait separately from CPU usage.
- Configure CPU alerts before systems become overloaded.
- Collect historical CPU metrics using monitoring platforms such as Prometheus and Grafana.
- Correlate CPU metrics with memory, disk, and application performance.
Common Mistakes¶
❌ Monitoring only total CPU utilization.
✅ Avoid this mistake: monitoring only total CPU utilization.
❌ Ignoring load average.
✅ Always review load average.
❌ Confusing CPU utilization with I/O wait.
✅ Distinguish clearly between CPU utilization with I/O wait.
❌ Never identifying CPU-intensive processes.
✅ Always identifying CPU-intensive processes.
❌ Ignoring gradual increases in processor utilization.
✅ Always review gradual increases in processor utilization.
Interview Questions¶
Beginner¶
- What does the
topcommand display? - What is CPU utilization?
- What does the
uptimecommand show? - Which command displays CPU hardware information?
Intermediate¶
- What is load average?
- What does high I/O wait indicate?
- How do you identify CPU-intensive processes?
- Why is per-core monitoring important?
Architect Level¶
- How would you monitor CPU utilization across hundreds of Linux servers?
- How would you troubleshoot a Kubernetes node with consistently high CPU usage?
- How would you determine whether a performance issue is caused by CPU, memory, or storage?
Summary¶
In this lesson, you learned:
- CPU monitoring fundamentals
- CPU utilization
- Load average
- Process CPU analysis
- Per-core monitoring
- CPU statistics
- Performance troubleshooting
- Production monitoring best practices
CPU monitoring is essential for maintaining high-performance Linux systems. By tracking processor utilization, load averages, CPU-intensive processes, and per-core performance, administrators can detect bottlenecks early, optimize workloads, and ensure reliable operation of production applications.
Key Takeaways¶
- Use
topandhtopfor real-time CPU monitoring. - Monitor system load using
uptime. - Analyze CPU statistics with
vmstatandmpstat. - Identify CPU-intensive processes using
ps. - Investigate sustained high CPU utilization and I/O wait.
- Combine CPU monitoring with memory, disk, and application metrics for comprehensive performance analysis.
What's Next?¶
Performance Troubleshooting — Diagnosing and Resolving Linux Performance Issues
You'll explore:
- Identifying performance bottlenecks
- CPU, memory, disk, and network analysis
- System performance methodology
- Troubleshooting tools
- Root cause analysis
- Performance optimization
- Production troubleshooting best practices
By the end of the lesson, you'll be able to systematically diagnose Linux performance issues, identify bottlenecks, determine root causes, and optimize production systems for reliability and efficiency.