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:
II. Installing the atop Tool
- openSUSE:
- Execute the installation command:
sudo zypper install -y atop atop-daemon - Start the atop service:
sudo systemctl start atopIf your distribution is not listed above, you can visit the official atop website for installation information.
- Execute the installation command:
III. Configuring 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.
III. Configure Monitoring Cycle and Log Retention Time
- Configuration Steps
- Execute the command to open the configuration file:
- In Alibaba Cloud Linux 3/2, CentOS 7/8, Fedora systems:
sudo vim /etc/sysconfig/atop - In Ubuntu, Debian, openSUSE, CentOS Stream 9, Rocky Linux 9 systems:
sudo vim /etc/default/atop
- In Alibaba Cloud Linux 3/2, CentOS 7/8, Fedora systems:
- Press ‘i’ to enter edit mode and adjust the configuration parameters according to your needs. For example, change the monitoring cycle to 30 seconds, set the log retention time to 7 days, and maintain the default log path:
- Press ‘Esc’ to return to normal editing mode, type
:wqto save and exit. - Restart the atop service to apply the configuration:
sudo systemctl restart atop
- Execute the command to open the configuration file:
LOGOPTS=""
LOGINTERVAL=30
LOGGENERATIONS=7
LOGPATH=/var/log/atop
Four. Using atop Tool
- Common Commands: In interactive command mode, the following commands are commonly used:
g: Return to the default comprehensive output view.c: Display the full command line for each process.m: Sort processes by memory usage in descending order.d: Sort processes by disk usage in descending order.a: Sort processes by overall resource usage in descending order.n: Sort processes by network usage in descending order.t: Jump to the next monitoring collection point.T: Jump to the previous monitoring collection point.b: Specify a timestamp in the formatYYYYMMDDhhmm.
Four. Using the atop Tool
- Resource Monitoring Field Meanings
- atop: Hostname, sampling date and time point.
- PRC: Overall process running status, including kernel state and user state runtime, total process count, number of processes in different states, etc.
- CPU: Overall CPU usage, the sum of the numbers is
N*100%(N is the number of CPU cores), including the proportion of time for kernel state, user state, interrupt, idle, and disk I/O waiting. - CPL: CPU load situation, such as the average number of processes in the queue over 1 minute, 5 minutes, and 15 minutes, context switch times, and interrupt occurrences.
- MEM: Memory usage, including total physical memory, free memory, page cache memory, file cache memory, and kernel occupied memory, etc. - SWP: Swap space utilization, including total swap area and available swap space size.
- PAG: Virtual memory page situation, such as inbound and outbound memory page numbers.
- DSK: Disk usage, with each disk device corresponding to a column, displaying device identifier, busy time proportion, read/write request quantity.
- NET: Network status, showcasing transport layer TCP and UDP, IP layer, and receive and send packet sizes for each active port.
Four. Using the atop Tool
- View Real-time System Metrics
- View system metrics every 5 seconds:
atop 5 - View system metrics from the last 30 intervals (each interval is 10 seconds) after the current time:
atop -M 10 30 - View system metrics from the last 10 minutes (10 intervals, each interval is 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 starts, collected records are stored by default in the
/var/log/atopdirectory. When viewing, be sure to specify the date of the log file must exist, otherwise it will error. - View daily historical metrics log:atop -r - View yesterday’s historical metrics log:
atop -r y - View historical metrics log for a specific date, such as November 6, 2024:
atop -r 20241106 - View historical metrics log from a specific date and time, such as starting from November 6, 2024, 14:00:
atop -r 20241106 -b 14:00 - View historical metrics log for a specified time range on a specific date, such as from November 5, 2024, 00:04 to 00:08:
atop -r 20241105 -b 00:04 -e 00:08## Four. Using the atop Tool - View Real-Time System Metrics
- View system metrics every 5 seconds:
atop 5 - View system metrics from the last 30 intervals (each interval is 10 seconds) after the current time:
atop -M 10 30 - View system metrics from the last 10 minutes (10 intervals, each interval is 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 starts, collected records are stored by default in the
/var/log/atopdirectory. When viewing, be sure to specify the log file for the desired date; otherwise, an error will occur.
Four. Using the atop Tool
- View System Activity Report
- View the CPU utilization report for the current system over 1 minute (12 times, with an interval of 5 seconds):
atopsar -c 5 12 - View the memory metrics report for a specified time period during the day, such as 18:00 to 18:01:
atopsar -m -b 18:00 -e 18:01 - View the memory metrics report for a specified date and time period, such as November 5, 2024 from 18:00 to 18:01:
atopsar -m -r 20241105 -b 18:00 -e 18:01
- View the CPU utilization report for the current system over 1 minute (12 times, with an interval of 5 seconds):
Five. Other Operations
- Configure Daily Log Rotation Policy: If you want to generate a daily
atopmetric log file, you can perform the following actions:- (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
logrotateor custom scripts to implement log management.
Five. Other Operations
- Load the optional netatop kernel module: If you need to monitor network usage, you can install the netatop module (the module is not installed by default in atop). As an 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:
V. Other Operations
The atop tool is powerful and flexible to use. By installing, configuring, and using it properly, we can better understand the running status of our Linux system and promptly identify and resolve potential issues. We hope this article will help everyone take Linux system monitoring to a new level.