In Linux system administration, real-time and comprehensive monitoring of system resources and process status is crucial. The atop tool, as a powerful monitoring powerhouse, helps us easily achieve this goal. This article will provide a detailed introduction on how to install, configure, and use the atop monitoring tool in a Linux instance.
I. atop Tool Introduction
atop is a tool specifically designed for monitoring Linux system resources and processes. It records the activity of systems and processes, and reports on the running status of all processes. The data collected by this tool covers resource usage such as CPU, memory, disk, and network, as well as process states. It can also save the data in log files to disk. For each process, we can obtain key information such as CPU utilization, memory growth, disk usage, priority, username, status, and exit code. Furthermore, through the atop configuration file, we can customize parameters such as logging collection frequency, log file storage path, and rotation strategy.
II. Installing the atop Tool
The installation method for atop varies slightly depending on the Linux distribution. The following provides an introduction based on common operating systems:
-
Alibaba Cloud Linux 3/2, CentOS 7/8, Fedora, Rocky Linux 9:
- Execute the installation command:
sudo yum install -y atop
- Start the atop service:
sudo systemctl start atop
- Execute the installation command:
-
Ubuntu / Debian:
- Update the software source list:
sudo apt update
- Execute the installation command:
sudo apt install -y atop
- Start the atop service:
sudo systemctl start atop
- Update the software source list:
-
CentOS Stream 9:
- Download and install:
sudo wget https://www.atoptool.nl/download/atop-2.11.0-1.el9.x86_64.rpm && sudo rpm -i atop-2.11.0-1.el9.x86_64.rpm
- Start the atop service:
sudo systemctl start atop
- Download and install:
-
openSUSE:
- Execute the installation command:
sudo zypper install -y atop atop-daemon
- Start the atop service:
sudo systemctl start atop
- Execute the installation command:
If your used distribution is not listed above, you can access the atop official website for installation information.
Three. Configure Monitoring Cycle and Log Retention Time
- Configuration File Location: In Alibaba Cloud Linux 3/2, CentOS 7/8, and Fedora systems, the atop configuration file is
/etc/sysconfig/atop
; in Ubuntu, Debian, and openSUSE systems, the configuration file is/etc/default/atop
. - Default Configuration Parameter Explanation
LOGOPTS
: Controls logging options for log files, defaults to empty.LOGINTERVAL
: Monitoring cycle, default 600 seconds. To collect historical logs for tracking issues, it’s recommended to adjust this frequency based on actual needs.LOGGENERATIONS
: Log retention time, default 28 days.LOGPATH
: Log file storage path, defaults to/var/log/atop
.
- Configuration Steps
- Execute the command to open the configuration file:
- In Alibaba Cloud Linux 3/2, CentOS 7/8, and Fedora systems:
sudo vim /etc/sysconfig/atop
- In Ubuntu, Debian, openSUSE, CentOS Stream 9, and Rocky Linux 9 systems:
sudo vim /etc/default/atop
- In Alibaba Cloud Linux 3/2, CentOS 7/8, and Fedora systems:
- Press ‘i’ to enter edit mode, adjust the configuration parameters according to your needs. For example, to change the monitoring cycle to 30 seconds, set the log retention time to 7 days, and maintain the default log path:
- Press ‘Esc’ key, input
:wq
, save and exit editing. - Restart the atop service to make the configuration effective:
sudo systemctl restart atop
- Execute the command to open the configuration file:
LOGOPTS=""
LOGINTERVAL=30
LOGGENERATIONS=7
LOGPATH=/var/log/atop
Four. Using the atop Tool
- Common Command Introduction: In interactive command mode, the following common commands are available:
g
: Return to the default comprehensive output view.c
: Display the complete command line for each process.m
: Sort processes in descending order by memory usage.d
: Sort processes in descending order by disk usage.a
: Sort processes in descending order by overall resource usage.n
: Sort processes in descending order by network usage.t
: Jump to the next monitoring collection point.T
: Jump to the previous monitoring collection point.b
: Specify a time point in the formatYYYYMMDDhhmm
.
- Resource Monitoring Field Meaning Introduction
- ATOP: Hostname, information sampling date and timepoint.
- PRC: Overall process running status, including kernel mode and user mode runtime, total number of processes, number of processes in different states, etc.
- CPU: Overall CPU usage, the sum of the numbers in each field is
N*100%
(N is the number of CPU cores), which includes the proportion of time for kernel mode, user mode, interrupts, idle, and waiting for disk IO. - CPL: CPU load situation, such as the average number of processes in the queue over 1 minute, 5 minutes and 15 minutes, the number of context switches, and the number of interrupts that occur.
- MEM: Memory usage, including total physical memory, free memory, page cache memory, file cache memory, kernel occupied memory, etc.
- SWP: Swap space usage, including swap area total size and available swap space size.
- PAG: Virtual memory paging situation, such as the number of swapped in and out memory pages.
- DSK: Disk usage, each disk device corresponds to a column, displaying the device identifier, busy state time proportion, read/write request quantity.
- NET: Network status, displays the TCP and UDP transmission layer, IP layer, and the receiving and sending packet sizes of each active port.
- View Real-time System Metrics
- View system metrics every 5 seconds:
atop 5
- View system metrics for the past 5 minutes (30 times in total, interval 10 seconds):
atop -M 10 30
- View system metrics for the past 10 minutes (10 times, interval 60 seconds) and write the results to a file:
atop -M 60 10 > /log/atop.mem
- View system metrics every 5 seconds:
- View Historical Metric Logs: After atop is started, recording data is stored by default in the
/var/log/atop
directory. When viewing, be sure to specify the date of the log file must exist, otherwise it will error.- View daily historical metric logs:
atop -r
- View yesterday’s historical metric logs:
atop -r y
- View historical metric logs for a specific date, such as 2024/11/06:
atop -r 20241106
- View historical metric logs from a specific time on a specific date, such as starting from 14:00 on 2024/11/06:
atop -r 20241106 -b 14:00
- View historical metric logs for a specific time period on a specific date, such as from 00:04 to 00:08 on 2024/11/5:
atop -r 20241105 -b 00:04 -e 00:08
- View daily historical metric logs:
- View System Activity Report
- View the CPU utilization report for the current system in 1 minute (12 times, interval 5 seconds):
atopsar -c 5 12
- View the memory metric report for a specific time period on a given day, such as from 18:00 to 18:01:
atopsar -m -b 18:00 -e 18:01
- View the memory metric report for a specific date and time period, such as from 18:00 to 18:01 on 2024/11/5: `atopsar -
- View the CPU utilization report for the current system in 1 minute (12 times, interval 5 seconds):
Five. Other Operations
-
Configure Daily Log Rotation Policy: If you want to generate an atop metric log file daily, perform the following steps:
- (Optional) Adjust monitoring period, log retention time, and log storage path according to your needs.
- Execute the command to enable and start the services related to daily log rotation:
sudo systemctl enable --now atop atopacct atop-rotate.timer
- If your business has more complex requirements for log processing, you can also combine it with logrotate or custom scripts to implement log management.
-
Load Optional netatop Kernel Module: If you need to monitor network usage, you can install the netatop module (this module is not installed by default in atop). For example, on Alibaba Cloud Linux 3:
- Install the kernel development package and the software environment required for compiling:
sudo yum install -y kernel-devel dkms elfutils-libelf-devel
- Download the latest version of netatop source code to a specified directory:
cd /usr/src/ && sudo wget https://www.atoptool.nl/download/netatop-3.2.2.tar.gz --no-check-certificate
- Extract the source code and enter the source code directory:
sudo tar -zxvf netatop-3.2.2.tar.gz && cd netatop-3.2.2
- Build and install the module and daemon based on the source code:
sudo make && sudo make install
- Start the netatop service:
sudo systemctl start netatop
- Install the kernel development package and the software environment required for compiling:
atop tool is powerful and flexible, and by installing, configuring, and using it properly, we can better understand the running status of the Linux system and promptly identify and solve potential problems. We hope this article will help everyone take Linux system monitoring to a new level.