If you work on Linux servers, you need to check the disk, CPU, and memory usage on your system. You can easily monitor these resources with simple terminal commands. However, you must decide whether you want to monitor CPU usage, memory usage, or disk usage. All of these terms can be different from each other. As a Linux system administrator, you are responsible for monitoring the performance of your system. In this article, we will learn how to monitor the CPU, RAM, and disk usage of your Linux system.

We have tested all the commands in this article on Ubuntu 22.04. So let’s get started!

Monitor Hard disk Usage on a Linux system

The following command-line tools are used to monitor the hard disk usage:

  • df
  • du
  • ls

Open the terminal by pressing ‘Ctrl Alt t’ and execute one by one the above-mentioned commands on it.

Use of df command

The ‘df’ is used to report how much disk space is used in a Linux system. When we use a filename with the ‘df’ command, it shows the free space on the disk partition where that file is saved. When the -h attribute is used with this command, it shows you the file and folders lists through which you can calculate the available disk space. Type the following command on the terminal to check available disk space:

$ df

<img alt="use df command to verify harddisk usage" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1467.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="454" src="data:image/svg xml,” width=”932″>

Use of du command

The ‘du‘ command is also used for Linux disk usage-related purposes. This command is slightly different from the df command. It displays the disk space that is already consumed by files on a disk instead of displaying available space. The following command can be used on the terminal to check the total used space:

$ du

<img alt="see folder usage using du command on Linux" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1468.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="837" loading="lazy" src="data:image/svg xml,” width=”943″>

Use of ls command

ls command is so simple and similar to the du command Linux can be used to list all directory contents along with the file size of each.

$ ls -l -h

<img alt="See file sizes with ls command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1469.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="449" loading="lazy" src="data:image/svg xml,” width=”947″>

Check CPU and Memory Usage on a Linux system

The following commands are used to monitor CPU utilization:

  • top
  • htop
  • mpstat
  • vmstat
  • sar

Use of top command

The top command is pre-installed on most of the latest Linux distributions that give you deep information about CPU utilization of your system. The top command gives you the live view of your total running services on your system. This command is specifically used to get information about how much memory is using each running process. It also provides you the complete details about CPU and memory utilization. Like a free command, it also displays the cache and buffer’s information. Type the following command to display the live information about CPU and memory:

$ top

Use ‘Ctrl C’ to stop the running process.

<img alt="memory usage shown in top command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1470.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="809" loading="lazy" src="data:image/svg xml,” width=”943″>

Use of htop command

Htop command is not installed by default on the Linux system. Therefore, you can install it by running the following command on the terminal:

$ sudo apt install htop

<img alt="htop command – a versatile tool for system monitoring" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1471.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="835" loading="lazy" src="data:image/svg xml,” width=”943″>

Type ‘Ctrl C’ to quit the running process.

Use of mpstat command

Before running mpstat command, you need to install sysstat packages on your system. For this purpose, type the following command that will install the required packages on your system:

$ sudo apt install sysstat

<img alt="The mpstat command in Linux" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1472.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="580" loading="lazy" src="data:image/svg xml,” width=”944″>

Mpstat command is used to report each available processor activity. If no activity is selected, then the complete CPU utilization summary in the form of a report to be displayed on your Linux system screen. Type the following command to check the all global average CPU activities:

$ mpstat

<img alt="mpstat command result" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1473.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="113" loading="lazy" src="data:image/svg xml,” width=”951″>

Use of vmstat command

The vmstat command is used to report information about memory, processes, block IO, paging, traps, and CPU activity. Type the following command on the terminal to monitor CPU usage:

$ vmstat

<img alt="vmstat command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1474.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="232" loading="lazy" src="data:image/svg xml,” width=”942″>

Use of sar command

Once the sysstat package is installed, you can also use the ‘sar’ command that is also included in this package. The ‘sar’ command is used to check the CPU utilization after a specified time interval.

Let’s explain with an example, you want to monitor CPU usage after every 5 seconds then, run the below-mentioned command on the terminal:

$ sar 5

Type ‘Ctrl C’ keys to stop the running process. The average CPU usage will be displayed on the terminal.

<img alt="sar command on Ubuntu" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1475.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="317" loading="lazy" src="data:image/svg xml,” width=”941″>

You can also limit the command to a specific number of iterations as follows:

$ sar 2 3

<img alt="Linux sar command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/11/echo/word-image-1476.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="217" loading="lazy" src="data:image/svg xml,” width=”945″>

In the above command, you will monitor the CPU usage after every 2 seconds for 3 iterations. The following output will show on the terminal:

Conclusion

In this article, we have shown how to monitor the memory, CPU, and Hard disk utilization on Ubuntu 22.04 Linux system. We have implemented different terminal commands on our system that can be used for resource monitoring.