How to How to Monitor the CPU on Ubuntu Server 20.04
Follow these steps to monitor the CPU
Step 1 : To start top, simply type in top in your command prompt and press Enter
top
Step 2 : You can use the htop command.
htop
Step 3 : The command pidstat can be used to monitor CPU utilization by an individual process or program. You will need to install sysstat
sudo apt install sysstat
pidstat -C mysql
Step 4 : With pidstat, you can also query statistics for a specific process by its process ID or PID, as follows:
pidstat -p 2809
Step 5 : The other useful command is vmstat
vmstat 1
Step 6 : Another command for getting processor statistics is mpstat.
mpstat 1 5
Step 7 : One more command, sar (System Activity Reporter), gives details of system performance. To get current CPU utilization using sar, specify the interval, and optionally, counter values.
sar -u 3 5
The command will output 5 records at an interval of 3 seconds.