top命令常用来监测CPU的负载,查看各个进程对CPU的占用情况
在centos7上执行top命令
第一行task一栏各个指标显而易见,不多解释
- load average:任务队列的平均长度,分别是1分钟,5分钟,15分钟内的平均长度,单核CPU以不超过1为宜,多核CPU以不超过CPU的个数为宜, 如果是8核CPU,这个值最好不要超过8,说明没有task被queued, 每个task都能及时的被响应。
- 如果这个值1 min > 5 min > 15 min,说明系统的task有越来越繁忙的趋势,反之亦然。
- 起初这个值只是用来表示CPU的需求,后来随着Linux的发展,这个值开始不仅包含running task,也包含uninterruptible state的task,这种uninterruptible state的task也包含等待disk/Network IO和其他block的状况,翻译过来也可以叫做非空闲等待的task,比如IO等待、资源争用,这些动作都非常耗CPU,导致CPU的上升。参考http://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html
第二行%CPU
- us: i.e. user ---time spent on un-nice user process
- sy: i.e. system ---time spent on 系统调用
- ni: i.e. nice ---time spent on nice user process
- id: i.e. idle ---time spent on idle status
- wa: i.e. IOwait ---time spent on IO waiting
- hi: i.e. hardwareInterrupt ---time spent on hardware interruption
- si: i.e. softwareInterrupt ---time spent on software interruption
- st: i.e. stolen ---被底层hypervisor占用的时间
nice和unnice的区别就是,越是nice的user process,优先级越低,因为它nice,它就越谦让;un-nice的user process优先级高,会越先争取到CPU的使用权。
第三行mem,记录mem内存信息
- buffers: 用作内核缓存的大小
第四行swap,
- total:总的交换空间的大小
- used:已经使用的交换空间的大小
- free:空闲的交换空间的大小
- cached:缓冲的交换空间大小
最后面的列表就是每个具体进程的资源占用情况
- PID: 进程号
- USER: 运行用户
- PR: 优先级,实际上是系统分给该进程的时间片个数
- NI: 该进程的nice程度
- RES: 物理内存占用量
- VIRT: 占用的虚拟内存量,虚拟内存占用量=swap区占用量+RES占用量
- SHR: shared 占用的共享内存总量
- S: status,S(sleep), R(running), Z(zombie), T(terminate)
- %CPU: 占用CPU的百分比
- %MEM: RES占用memory的百分比
- TIME+ :累积CPU占用时间