Linux系统状态查看工具-atop
atop是一个功能非常强大的linux服务器监控工具,它的数据采集主要包括:CPU、内存、磁盘、网络、进程等,并且能提供非常详细的内容,同时能以日志文件的方式保存在磁盘中,服务器出现问题后,可获取相应的atop日志文件进行分析。特别是当有部分存在压力它会以特殊的颜色进行展示,如果颜色是红色那么说明已经很严重了。需要注意的是:界面所有的信息都是反映过去10秒的状态信息。atop在安装完毕后,会自动成为一个服务,有几个重要的配置文件,通常默认在如下路径:/etc/sysconfig/atopAtop is an ASCII full-screen performance monitor for Linux that is capable of reporting the activity of all processes (even if processes have finished during the interval), daily logging of system and process activity for long-term analysis, highlighting overloaded system resources by using colors, etc. At regular intervals, it shows system-level activity related to the CPU, memory, swap, disks (including LVM) and network layers, and for every process (and thread) it shows e.g. the CPU utilization, memory growth, disk utilization, priority, username, state, and exit code.

atop配置文件主要用于调整atop监控周期,默认600s采集一次。atop在启动之后,会将采集记录在 /var/log/atop目录中,可执行如下命令查看日志文件
atop -r /var/log/atop/atop_20200331
The command atop has some major advantages compared to other performance monitoring tools:
Resource consumption by all processes
It shows the resource consumption by all processes that were active during the interval, so also the resource consumption by those processes that have finished during the interval.
Utilization of all relevant resources
Obviously it shows system-level counters concerning utilization of cpu and memory/swap, however it also shows disk I/O and network utilization counters on system level.
Permanent logging of resource utilization
It is able to store raw counters in a file for long-term analysis on system level and process level. These raw counters are compressed at the moment of writing to minimize disk space usage. By default, the daily logfiles are preserved for 28 days.System activity reports can be generated from a logfile by using the atopsar command.
Highlight critical resources
It highlights resources that have (almost) reached a critical load by using colors for the system statistics.
Scalable window width
It is able to add or remove columns dynamically at the moment that you enlarge or shrink the width of your window.
Resource consumption by individual threads
It is able to show the resource consumption for each thread within a process.
Watch activity only
By default, it only shows system resources and processes that were really active during the last interval, so output related to resources or processes that were completely passive during the interval is by default suppressed.
Watch deviations only
For the active system resources and processes, only the load during the last interval is shown (not the accumulated utilization since system boot or process startup).
Accumulated process activity per user
For each interval, it is able to accumulate the resource consumption for all processes per user.
Accumulated process activity per program
For each interval, it is able to accumulate the resource consumption for all processes with the same name.
Network activity per process
In combination with the optional kernel module netatop, it shows process-level counters concerning the number of TCP and UDP packets transferred, and the consumed network bandwidth per process.
下为我机器上的一例输出:
ATOP - freeoa 2020/03/31 12:48:03 -------------- 10s elapsed
PRC | sys 0.06s | user 0.13s | #proc 129 | #trun 1 | #tslpi 199 | #tslpu 0 | #zombie 0 | clones 14 | | #exit 11 |
CPU | sys 1% | user 2% | irq 0% | idle 198% | wait 0% | guest 0% | ipc 1.02 | cycl 27MHz | curf 800MHz | curscal 28% |
cpu | sys 0% | user 1% | irq 0% | idle 98% | cpu000 w 0% | guest 0% | ipc 1.06 | cycl 39MHz | curf 800MHz | curscal 28% |
cpu | sys 1% | user 0% | irq 0% | idle 99% | cpu001 w 0% | guest 0% | ipc 0.95 | cycl 16MHz | curf 800MHz | curscal 28% |
CPL | avg1 0.00 | avg5 0.02 | avg15 0.00 | | | csw 2408 | intr 1664 | | | numcpu 2 |
MEM | tot 3.8G | free 196.7M | cache 3.2G | buff 1.1M | slab 184.1M | shmem 36.4M | shrss 5.0M | vmbal 0.0M | hptot 0.0M | hpuse 0.0M |
SWP | tot 3.7G | free 3.6G | | | | | | | vmcom 1.4G | vmlim 5.6G |
LVM | -lv--sysroot | busy 0% | read 0 | write 1 | KiB/r 0 | KiB/w 4 | MBr/s 0.0 | MBw/s 0.0 | avq 0.00 | avio 0.00 ms |
DSK | sda | busy 0% | read 0 | write 1 | KiB/r 0 | KiB/w 4 | MBr/s 0.0 | MBw/s 0.0 | avq 0.00 | avio 0.00 ms |
NET | transport | tcpi 414 | tcpo 452 | udpi 17 | udpo 18 | tcpao 13 | tcppo 3 | tcprs 6 | tcpie 0 | udpie 0 |
NET | network | ipi 476 | ipo 464 | ipfrw 0 | deliv 465 | | | | icmpi 0 | icmpo 0 |
NET | eth0 0% | pcki 337 | pcko 310 | sp 100 Mbps | si 56 Kbps | so 49 Kbps | erri 0 | erro 0 | drpi 1 | drpo 0 |
NET | lo ---- | pcki 169 | pcko 169 | sp 0 Mbps | si 37 Kbps | so 37 Kbps | erri 0 | erro 0 | drpi 0 | drpo 0 |
PID SYSCPU USRCPU VGROW RGROW RDDSK WRDSK RUID EUID ST EXC THR S CPUNR CPU CMD 1/1
16283 0.01s 0.10s 0K 0K - - root - NE 0 0 E - 1% <perl>
495 0.01s 0.02s 0K 0K 0K 0K root root -- - 10 S 0 0% frpc
574 0.00s 0.01s 0K 0K 0K 4K lightdm lightdm -- - 4 S 1 0% lightdm-gtk-gr
511 0.01s 0.00s 0K 4K 0K 0K root root -- - 4 S 0 0% Xorg
489 0.01s 0.00s -40.0M -92K 0K 0K privoxy privoxy -- - 81 S 1 0% privoxy
16192 0.01s 0.00s 0K 0K 0K 0K root root -- - 1 R 0 0% atop
20254 0.01s 0.00s 0K 0K 0K 0K luohongd luohongd -- - 1 S 0 0% sshd
280 0.00s 0.00s 0K 0K 0K 0K root root -- - 1 S 0 0% systemd-journa
452 0.00s 0.00s 0K 0K 0K 0K root root -- - 3 S 1 0% accounts-daemo
450 0.00s 0.00s 0K 0K 0K 0K messageb messageb -- - 1 S 1 0% dbus-daemon
447 0.00s 0.00s 0K 0K 0K 8K root root -- - 4 S 1 0% rsyslogd
449 0.00s 0.00s 0K 0K 0K 4K root root -- - 1 S 0 0% cron
13524 0.00s 0.00s 0K 0K 0K 0K root root -- - 1 S 0 0% atopacctd
10 0.00s 0.00s 0K 0K 0K 0K root root -- - 1 I 1 0% rcu_sched
243 0.00s 0.00s 0K 0K 0K 0K root root -- - 1 S 1 0% xfsaild/dm-0
13329 0.00s 0.00s 0K 0K 0K 0K root root -- - 1 I 1 0% kworker/u4:1-f
13411 0.00s 0.00s 0K 0K 0K 0K root root -- - 1 I 1 0% kworker/1:2-ev
16016 0.00s 0.00s 0K 0K 0K 0K root root -- - 1 I 0 0% kworker/0:2-ev
16284 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <df>
16286 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <ps>
16287 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <wc>
16285 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <sh>
16289 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <ps>
16290 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <wc>
16288 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <sh>
16291 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <ss>
16282 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <sh>
16281 0.00s 0.00s 0K 0K - - root - NE 0 0 E - 0% <cron>
常用参数(在交互模式下也可以用这些参数)(有些功能需要打了内核补丁才能使用)
-n 显示网络信息
-m 显示内存相关信息
-d 显示磁盘读写相关
-g 查看默认的通用输出
-s 显示调度特点:每个进程的以下字段所示:进程的ID,运行状态(R)的线程数、中断状态的睡眠线程S(TLSPI)和不可中断睡眠线程D (TSLPU) 数,调度策略(分时调度策略,实时时间片轮转策略,实时调度策略FIFO),nice值,优先级(PRI),实时优先级(RTPR),当前的处理器,状态,退出代码,进程状态,cpu利用率和进程名。
-v 显示各种进程特性:每个进程的以下字段所示:进程ID(PID),父进程ID(PPID)、用户名(USERNAME)和组(GROUP),开始日期和时间,状态(例如,退出代码,如果该进程已完成),进程状态(ST)(D:不可终止进程、R:正在运行进程 、T:暂停进程、S:休眠进程、Z:僵尸进程……),CPU占用率和进程名。
-c 以命令行command-line的形式显示:每个进程有以下字段所示:进程的ID,所选资源占用百分比和命令行参数,
-u 以用户的形式显示:以下字段显示:在上一间隔时间内活动或终止的进程数,上一时间间隔内cpu在系统模式和用户模式的消耗,活动进程对虚拟内存和现有内存的消耗。当安装的cnt补丁后会显示读(RDDSK)写(WRDSK)到磁盘上的数据量,以及所收到(RNET)和发送(SNET)的网络数据包,内核补丁没有安装时这些计数器为零。最后一栏显示CPU百分比和用户名。
-p 以进程名的形式显示信息:和-u类似只是最后显示的是进程名
-M 按照占用物理内存百分比大小进行排列
-D,按照访问磁盘的繁忙程度进行排序
-N 按照接受和发送的网络数据包排序
-A 依据当前系统最繁忙的资源进行排序,可能有ACPU、AMEM、ADSK或者ANET
在交互模式下的可用选项:
c 按照进程cpu使用率进行降序筛选
m按照进程内存使用率进行降序筛选
d 按照进程磁盘使用率进行降序筛选
a 按照进程资源综合使用率进行降序筛选
n 按照进程网络使用率进行降序筛选(需要额外安装内核模块才支持,默认不支持)
t 跳转到下一个监控采集点
T 跳转到上一个监控采集点
B 指定时间点,格式 hh:mm:ss
监控字段的含义
atop:改行列出了服务器的host、当前时间、信息收集的频率
PRC:该列展示整个系统的性能状况
sys:过去10s所有的进程在内核态运行的时间总和
usr:过去10s所有的进程在用户态的运行时间总和
#proc:进程总数
#trun:过去10s转换的进程数
#zombie:过去10s僵死进程的数量
#exit:在10s采样周期期间退出的进程数量
CPU:cpu列展示了服务器的CPU整体的一个状态信息,包括内核和用户所占的比例、处理中断所占的比例、CPU的处于空闲下比例(这里是100%*cpu核心数,CPU有时候也会因为由于磁盘性能问题出现等待的空闲)
sys:cpu在处理进程时处于内核态的时间所占的比例
usr:cpu在处理进程时处于用户态的时间所占的比例
irq:cpu在处理进程的中断请求所占的实际比例
idle:cpu处于空闲状态下的时间比例(除了本身空闲,还有比如等待磁盘io的情况下也会处于空闲状态)
cpu:每个核心的状态信息,和总的CPU信息一样,每列加起来的总和就是总的CPU的状态信息。
CPL:cpl也反应了服务器整体的性能,展示信息包括进程等待队列数,分别从过去1分钟、5分钟、15分钟的采样信息。
avg1:过去1分钟进程等待队列数
avg5:过去5分钟进程等待队列数
avg15:过去15分钟进程等待队列数
csw(context swapping):上下文交换次数
intr(interrupt):中断发生的次数
numcpu:cpu的核心数
mem:该列主要展示内存的使用信息
tot:物理内存总量
free:空闲内存的大小(不能单单从这个字段就判断内存不足,还需要参考free -m中的-/+ buffers/cache:free因为这块的内容随时就可以拿过来使用,还可以从是否有使用Swap来判断是否内存不足)
cache:用于页缓存的内存大小
dirty:内存中的脏页大小
buff:用于文件缓存的内存大小
slab:系统内核占用的内存大小
SWP:交换空间使用情况
tot:交换空间总量
free:交换空间剩余空间总量
PAG列:虚拟内存分页情况
swin:换入内存页数
swout:换出内存页数
LVM/DSK:每个分区信息以一列来进行展示
busy:磁盘忙时所占比例
read、KiB/r 、MBr/s:每秒读的请求数和请求的kb、mb数
write、KiB/w 、MBr/w:每秒写的请求数和请求的kb、mb数
avq:磁盘平均队列长度(根据实际的监控该列好像是磁盘平均请求数avgrq)
avio:磁盘的平均io时间
NET:展示了传输层(TCP/UDP)、网络层(ip)、网络接口的网络传输信息
transport:传输层(TCP/UDP)的数据输入输出的展示,例如在服务器的内部进程之间的数据传输就是在传输层展示,以为还不需要往下通过网络进行传输
network:网络层(ip)的数据输入输出的展示
eth0:默认的网络接口的数据输入输出的展示,也就是通过etho的ip的数据传输的展示
sp:网卡的带宽(1000M)
pcki:传入的数据包的大小
pcko:传出的数据包的大小
si:每秒传入的数据大小
so:每秒传出的数据大小
coll(collisions):每秒的冲突数
mlti(MULTICAST):每秒的多路广播的数量
erri/erro:每秒输入输出的错误数
drpi/drpo:每秒的输入输出的丢包数
lo:通过127.0.0.1网络接口的数据传输的数据展示,参数和上面的eth0是一样的
相关的进程列展示
进程列展示了每个进程在过去10S内的数据,在atop的展示页面也可以输入m(内存)、p(进程)、u(用户)、d(磁盘)、c(进程运行的代码)、v(线程) 进行页面切换。
m模式:内存状态模式
SYSCPU:过去10s内进程处于内核模式占用的CPU时间
USRCPU:过去10S进程处于用户模式占用的CPU时间
VSIZE:过去10S进程占用的虚拟空间大小
RSIZE:过去10S进程占用的内存空间大小
PSIZE:过去10S进程占用的页大小
VGROW:过去10S进程增长的虚拟空间大小
RGROW:过去10S进程增长的内存大小
SWAPSZ:过去10S进程使用交换空间的大小。
MEM:过去10S进程占用内存百分比
d模式:磁盘状态模式
RDDSK:过去10S进程读磁盘的数据量
WRDSK:过去10S进程写磁盘的数据量
DSK:过去10S进程所占磁盘的百分比
CMD:进程名
p模式:进程状态模式,同一个名称的进程显示一列,根据进程名进行分组显示
NPROCS:相同名称的进程数量
其它的参数上面已经有列出
v模式:线程状态模式
u模式:用户模式
根据用户进行分组显示
g模式:标准模式
s:进程当前的状态,包括:s(sleeping),R(runing)等
atop的相关文件:
/etc/atop:目录保存的是atop的配置文件
/etc/rc.d/init.d/atop:atop的启动文件
/etc/cron.d/atop:atop的定时任务文件,默认是每天0点开始
/var/log/atop:atop日志文件,默认是每天0点开始会产生当天的一个日志文件,然后可以通过 atop -r file 查看信息,但是没有找到自动播放的的功能,只能通过输入b显示一个指定的时间的信息,可以用一个循环来实现
/usr/bin/atop:atop命令目录
atop -r atop_20200331 -b 13:00 -e 17:00
atop产生的日志文件信息是10分钟一个采样周期进行记录,可以通过修改/etc/atop/atop.daily文件进行修改。
Other useful commands:
Launch with average-per-second total values:
atop -1
Launch with active processes only:
atop -a
Launch with command line per process
atop -c
Launch with disk info
atop -d
Launch with memory info
atop -m
Launch with network info
atop -n
Launch with scheduling info
atop -s
Launch with various info (ppid, user, time)
atop -v
Launch with individual threads
atop -y
Once atop is running, press the following shortcut keys to sort processes:
a – sort in order of most active resource.
c – revert to sorting by cpu consumption (default).
d – sort in order of disk activity.
m – sort in order of memory usage
n – sort in order of network activity
最新版本:3.0
官方主页:https://atoptool.nl/