If your computer or Linux server is slow, the first thing to look for is CPU usage. CPU stands for Central Processing Unit, and it is the mind of your computer. If it becomes too busy, your computer may freeze or slow down.

Here in this article, we will demonstrate easy steps to track CPU usage in Linux. You don't need to be a Linux expert to follow these steps.

 

Why to Monitor CPU Usage?

CPU usage monitoring helps you:

  • Find out if your system is overworking.

  • Find out which programs are using the most CPU.

  • Prevent system crashes and slowdowns.

  • Improve performance and planning for an upgrade.

 

Common Commands to Monitor CPU Usage

Linux has several inbuilt monitors for CPU usage. Here are the most frequently used ones:

1. top

top shows current information about your system.

How to use:

top

You can see a list of running processes and how much CPU each one is using. Look at the line starting with %Cpu(s) for all CPU usage.

Hit q to Exit.

 

2. htop (a more advanced version of top)

htop is similar to top, but more readable and convenient.

How to install:

sudo apt install htop # Debian/Ubuntu
sudo yum install htop # CentOS/RHEL

How to use:

htop

You will get a colorful output displaying CPU usage, memory, and processes. Scroll using arrow keys. Press q to exit.

 

3. mpstat

mpstat displays CPU usage on multiple cores.

How to install:

sudo apt install sysstat

How to use:

mpstat

It shows CPU usage over time. This is useful if your system has more than a single CPU core.

 

4. iostat

iostat displays both CPU and disk usage.

How to install:

sudo apt install sysstat

How to use:

iostat

This command lets you see if the CPU is waiting on disk operations.

5. vmstat

vmstat shows system performance in a simple format.

How to use:

vmstat 1 5

This shows system stats every second, five times. Look at the us and sy columns for CPU usage by users and the system.

 

Conclusion

Keeping an eye on your CPU usage helps keep your Linux system running smoothly. Whether you're using a small VPS or a large dedicated server, tools like top, htop, and mpstat can help you detect and fix problems fast.

Start using these commands today to make sure your system stays healthy and fast!