This article describes how to monitor resource usage using the top and atop commands.

Method 1: Using the top command

The top program is the conventional way of displaying resource use information on Linux. The top program displays system statistics and a list of current processes in real time. You can also customize which information top displays.

To start top, log in to your account using SSH, and then type the following command:

top

By default, top updates the displayed information every 3 seconds. There are many commands for manipulating the information that top displays. For example, to sort tasks by CPU usage, type P.

To view detailed information about using the top command, type the following command:

man top

Method 2: Using the atop command

The atop program is similar to the well-known top program, but it has many extra features. Like top, atop displays a real-time summary of the system's resource usage. However, atop displays more detailed information, as well as several ways to view and filter that information. Additionally, atop runs a background process that maintains system activity log files. You can access these system activity logs in atop to view past resource usage information.

To start atop, log in to your account using SSH, and then type the following command:

atop

When you start atop for the first time, the amount of information displayed can be a little overwhelming. Here is a quick summary of the information atop displays:

  • The top line displays the server name, as well as the date and time of the last data sample.
  • The PRC row displays general statistics, such as time spent in system calls (sys) and user space (user). This line also displays the total number of processes (#proc) and zombie processes (#zombie).
  • The CPU and cpu rows display statistics for each CPU.  Each row shows the percentage of time a CPU has spent doing various tasks such as system calls (sys), user space processing (user), servicing hardware interrupts (irq), doing nothing (idle), and waiting for disks (cpuXXX w).
  • The CPL row displays the weighted load average for the past 1, 5, and 15 minutes. It also shows the number of context switches (csw). Context switches occur when the processor switches between kernel space and user space.
  • The MEM row displays memory usage information.
  • The SWP row displays swap memory usage information.
  • The PAG row displays paging memory frequency, and should appear rarely on a healthy server.
  • The DSK row displays disk usage information.
  • The NET rows display usage statistics for each network interface.

To view complete reference information for the atop command, type the following command:

man atop
View server activity history

The atop program maintains activity logs for the past few days. If your web site started experiencing problems yesterday, for example, you could load yesterday's resource usage data into atop and view what was happening on the system at the time.

To view the server's activity for today, type the following command:

atop -r

After atop loads the server history, you can move forward through the history by typing t (lowercase t). Note that the time at the top of the screen moves forward. To move backward through the history, type T (uppercase T).

To view the server history starting at a specific time, start atop with the -b option. For example, to view the server activity for today starting at 11:15, type the following command:

atop -r -b 11:15

To view resource usage for days in the past, list the files in the /var/log/atop directory to see which days are available. Then start atop using the -r option and the specified log file. For example, the following command instructs atop to load resource usage data for July 16, 2023:

atop -r /var/log/atop/atop_20230716
Was this answer helpful? 0 Users Found This Useful (0 Votes) linux, resource usage