Skip to content

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

Linux Mastery → Module 12: Monitoring & Logs → Lesson 7

Difficulty: Beginner → Intermediate

Reading Time: 95 Minutes

Course Progress

Course: Linux Mastery

Module: Monitoring & Logs

Lesson: 7 of 10


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:

CPU Usage Reaches 100%


Application Response Time Increases


Users Experience Timeouts

With monitoring:

CPU Usage


Alert at High Utilization


Identify Problem Process


Optimize


Stable Performance

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

Processes


CPU Scheduler


Processor


Execution


Performance Metrics

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:

top

Example:

%Cpu(s):

us

sy

id

wa

Press:

Shift + P

Sort processes by CPU usage.


Monitor CPU with htop

htop

Features:

  • Per-core CPU graphs
  • Interactive process management
  • Colorized display
  • Easy sorting

Check System Load

Use:

uptime

Example:

load average:

0.45

0.60

0.70

The three values represent the average system load over:

  • 1 minute
  • 5 minutes
  • 15 minutes

Understanding Load Average

Example:

4 CPU Cores


Load Average

4.00


System Fully Utilized

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:

vmstat

Example:

vmstat 2

Useful CPU columns:

us

sy

id

wa

Detailed CPU Statistics

Install sysstat if necessary.

mpstat

Per-core statistics.

mpstat -P ALL

Displays utilization for every CPU core.


CPU Usage by Process

Display the highest CPU consumers.

ps aux --sort=-%cpu

Top 10:

ps aux --sort=-%cpu | head

View CPU Information

Display processor details.

lscpu

Example output:

Architecture

CPU(s)

Model Name

Thread(s)

Core(s)

Number of CPUs

nproc

Example:

8

CPU Frequency

cat /proc/cpuinfo

Search frequency.

grep "cpu MHz" /proc/cpuinfo

Real-Time CPU Monitoring

Refresh every second.

watch -n 1 grep "cpu " /proc/stat

CPU Information from proc

Detailed CPU statistics.

cat /proc/stat

Useful for low-level monitoring.


Common Commands

Monitor CPU.

top

System load.

uptime

CPU statistics.

vmstat

Per-core monitoring.

mpstat -P ALL

CPU information.

lscpu

Real Production Examples

Monitor CPU usage.

top

Check system load.

uptime

View per-core usage.

mpstat -P ALL

Find CPU-intensive processes.

ps aux --sort=-%cpu | head

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.

top

Press:

Shift + P

Sort by CPU usage.


Task 2

Display system load.

uptime

Task 3

Monitor CPU statistics.

vmstat 2

Task 4

Display processor information.

lscpu

Task 5

Display the number of CPU cores.

nproc

Task 6

Monitor per-core utilization.

mpstat -P ALL

Task 7

Display the top CPU-consuming processes.

ps aux --sort=-%cpu | head

Task 8

Review /proc/stat.

cat /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:

top

Result:

CPU


95%


Java Process

Next:

ps aux --sort=-%cpu | head

The Java application is consuming nearly all available CPU resources.

Further investigation reveals an inefficient query causing excessive processing.

After optimizing the application:

CPU Usage


Normal


Response Time Improved

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

  1. What does the top command display?
  2. What is CPU utilization?
  3. What does the uptime command show?
  4. Which command displays CPU hardware information?

Intermediate

  1. What is load average?
  2. What does high I/O wait indicate?
  3. How do you identify CPU-intensive processes?
  4. Why is per-core monitoring important?

Architect Level

  1. How would you monitor CPU utilization across hundreds of Linux servers?
  2. How would you troubleshoot a Kubernetes node with consistently high CPU usage?
  3. 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 top and htop for real-time CPU monitoring.
  • Monitor system load using uptime.
  • Analyze CPU statistics with vmstat and mpstat.
  • 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.