Linux中atop命令的使用指南
atop命令是Linux系统资源监控工具,它显示与系统资源负载量相关的大量信息,并可在进程级别进行监控。掌握此实用程序对用户来说具有无限优势。
首先,我们必须在系统上安装atop命令。Debian/Ubuntu用户可以通过以下方式完成安装:
sudo apt install atop
其他Linux用户可以使用他们的标准软件包管理器,然后输入“atop”关键词。
这个命令具有显示系统相关多个机密信息的功能。为了防止数据被窃取,我们可以使用’sudo su’或’sudo -s’获得提升的访问权限。关于sudo,我们有完整的文档。
atop命令的基本输出
为了显示系统资源的所有进程级使用情况,我们可以在终端中简单地运行’atop’命令。
atop
如我们所见,整个布局分为两个面板。上面的面板提供了系统资源的累积使用情况,而下面的面板则显示了每个进程的细分信息。让我们来看看每一个。
atop命令的累积统计数据
这个视图中的每个条目都集中于特定的系统资源。
1. 流程相关的统计数据
- PRC – stands for “process”.
The first two values are the time consumed by the ‘sys’ (system) and ‘user’ processes.
It is followed by the total number of processes as ‘#proc’.
The next value is the number of threads currently running in the system. (‘#trun’)
‘#tslpi’ denotes the number of threads that are currently sleeping and interruptible.
‘#tslpu’ denotes the number of threads that are currently sleeping and uninterruptible.
The following value is the number of zombie processes.
Next up is the number of clone system calls.
The last value is the number of processes that ended during the elapsed time. (‘#exit’)
2. 与表现相关的统计数据
- CPU – relates to CPU utilization.
The first two values show the percentage utilization of all the cores by the system and user processes.
The percentage of CPU used for interrupt requests. (‘irq’)
The next value is the idle percentage for all the cores combined.
The following value denotes the waiting each CPU core had to do.
Next up is the percentage for the steal time.
‘guest’ denotes the guest-percentage, which is the CPU time spent on other virtual machines.
The last two values indicate the current frequency of the CPU. - Now, the ‘atop’ displays the above statistics for each core independently.
- CPL – refers to as CPU Load.
The first three values are the average loads with different periods: 1, 5, and 15 minutes.
This is followed by the number of context switches (‘csw’)
Next up is the number of interrupts (‘intr’)
The last value is number of available CPUs.
3. 与记忆相关的统计资料
-
MEM – Memory Utilization
The total physical memory supported.
The memory currently free.
The current cache memory.
‘buff’ as in “buffer” is the amount of memory consumed in filesystem meta-data.
The sum of memory for kernel’s memory allocation shown as ‘slab’.
The amount of shared memory.
- SWP – Swap Memory.
3. 与硬盘有关的统计数据
- DSK – Disk usage
The first value denotes the percentage of time the system is busy handling requests.
The reading requests issued.
The writing requests issued.
The rate at which data (in KB) is read per reading request.
The rate at which data (in KB) is written per writing request.
The next two values are time rates for reading and writing on the disk in Megabytes.
The last value is the average number of milliseconds spent in handling requests.
4. 网络相关统计数据
- NET – Network Statistics at the Transport Layer
‘transport’ signifies the Transport layer in Networking, which deals with the data protocols.
The number of segments received by the system following the TCP protocol. (‘tcpi’)
The number of segments transmitted. (‘tcpo’)
The similar statistics for UCP protocol. (‘udpi’ for UDP in) and (‘udpo’ for UDP out).
‘tcpao’ is the number of active TCP open connections.
Opposite to previous ‘tcppo’ is the number of passive TCP connections, but still open.
The figure of TCP retransmissions as ‘tcprs’.
The figure of UDP input errors as ‘udpie’. - NET – Network Statistics at the Network Layer
‘network’ signifies the Network Layer, which deals with Internet Protocols, IPv4 and IPv6 combined.
The number of IP packets received by the network interfaces. (‘ipi’)
The number of IP packets transmitted out from the interfaces. (‘ipo’)
The quantity of IP packets forwarded to other interfaces. (‘ipfrw’)
The quantity of IP packets delivered. (‘deliv’)
The last two entries are the number of ICMP packets received and transmitted by the network interfaces. - The following lines refer to each active network interface.
The first value is the name of the network interface, like ‘wlp19s0’.
The following two packets are the number of packets that were received and transmitted through the particular interface. (‘pcki’ and ‘pcko’)
The network speed in Megabits (Mbps) as ‘sp’.
The rate at which bits are received and transmitted per second. (‘si’ and ‘so’)
The number of errors in packets received and transmitted. (‘erri’ and ‘erro’).
The last two values are the dropped packets in both ways. (‘drpi’ and ‘drpo’)
这就是对atop命令的顶部面板解释的总结。
每个进程的系统资源
值得注意的是,在一定时间间隔后,“atop”命令中的值会不断更新。
‘atop’命令的通用输出为每个进程条目显示以下细节:
- PID – The process ID.
- SYSCPU – The amount of CPU consumed by the process while system handling.
- USRCPU – The amount of CPU consumed by the process, during its running in user mode.
- VGROW – The amount of virtual memory that the process has occupied since the last value update.
- RGROW – The amount of resident (physical) memory grown since last value update.
- RDDSK – The size of data transferred during disk reads.
- WRDSK – The size of data transferred during disk writes.
- RUID – The real user ID under which the process is being executed.
- EUID – The effective user ID under which the process is being executed.
- ST – The current status of the process.
- EXC – The exit code after the process terminates
- THR – The number of threads within the process.
- S – The current status of the primary thread of the process.
- CPU – The percentage of CPU utilization of the entire process.
- CMD – The name of the process.
在这个通用输出中,进程是根据 CPU 利用率的百分比排序的。从这个特定的输出中,我们可以看到,对于每种类型的系统资源,我们只获得了很少的信息。
让我们尝试研究每种类型系统资源的流程级信息。
atop命令的基于内存的输出
使用”atop”命令可以研究系统中每个正在运行的进程的内存消耗。我们可以通过运行以下命令来实现:
atop -m
正如我们所见,即使我们添加了内存选项“-m”,顶部面板仍保持不变。现在让我们了解每个进程条目的列。
- PID – The process ID.
- TID – The thread ID.
- MINFLT – The number of minor page faults that have been solved by accessing data from free pages.
- MAJFLT – The number of major page faults that have been solved by especially retrieving data from disk.
- VSTEXT – The virtual memory occupied by the process text.
- VSLIBS – The virtual memory occupied by the shared libraries of the process.
- VDATA – The virtual memory size of the private data of the process.
- VSTACK – The virtual memory size of the private stack of the process.
- VSIZE – The total virtual memory size of the process.
- RSIZE – The total resident memory occupied by the process.
- MEM – The percentage of RAM consumed by the process.
根据“MEM”列对进程进行排序。
由于“atop”在某种程度上是一个交互式命令实用程序,我们可以在其中更改列。我们所要做的就是在显示信息时输入特定选项。
例如,在终端上运行“atop”之后,我们只需输入“m”即可切换到与内存相关的输出。
在Linux中使用原子命令的磁盘特定输出
为了提取与磁盘使用相关的信息,我们可以使用’atop’命令的’-d’选项。
atop -d
在磁盘特定的输出中,并没有很多需要注意的内容。其中一些关键发现包括:
- RDDSK – The size of data transferred during disk reads.
- WRDSK – The size of data transferred during disk writes.
- WCANCL – The size of data initially written, but later withdrawn
- DSK – The percentage of Disk occupied.
- CMD – The name of the process.
必须注意,进程是根据“DSK”列排序的。
使用atop命令查找在后台运行的命令。
这提供了以命令行输出格式展示的在后台运行的进程命令。
atop -c
如果你复制粘贴“命令行”列下的代码,就可以重新运行相同的进程。这个输出能告诉我们具体是哪个命令在后台启动了该进程。
基于线程的信息
与仅仅检查进程信息不同,atop命令提供了检查特定线程资源利用率的能力。要访问该输出,我们可以运行以下命令之一:
atop -y
当命令已经显示系统资源信息时,您可以选择按下“y”键。
很明显,系统资源列的任何一个都没有发生变化。只增加了各自进程的线程数量。
杂项信息
使用’atop’命令可以提取许多种信息。其中一些有用的信息包括:
找到进程的启动时间
通过使用“-v”选项,我们可以获取进程的特征。
atop -v
每个用户在系统中的进程数量
atop -au
3. 进程正在运行的核心是哪个?
这种特定类型的信息属于进程的调度特征。可以通过使用“-s”选项来访问。
atop -s
几个“高手”的小把戏
有一些“atop”命令的技巧可能会很有用:
- Pausing the ‘atop’ screen – using ‘z’ key.
- Changing the time interval of value updates – using ‘i’ key followed by the number of seconds, we wish to change it to.
- Interrupt to instantly update the values – using ‘t’ key.
- Quitting the display – using ‘q’ key.
结论
我们知道,“atop”命令对于任何Linux用户来说可能会难以处理。学习这个强大命令需要耐心和毅力。如果有任何疑问,请随时在评论区留言给我们。