mpstat 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

mpstat 命令安装:


  1. -bash/zsg: mpstat: command not found
  2.  
  3. #Debian
  4. apt-get install sysstat
  5.  
  6. #Ubuntu
  7. apt-get install sysstat
  8.  
  9. #Alpine
  10. apk add sysstat
  11.  
  12. #Arch Linux
  13. pacman -S sysstat
  14.  
  15. #Kali Linux
  16. apt-get install sysstat
  17.  
  18. #CentOS
  19. yum install sysstat
  20.  
  21. #Fedora
  22. dnf install sysstat
  23.  
  24. #OS X
  25. brew install sysstat
  26.  
  27. #Raspbian
  28. apt-get install sysstat
  29.  
  30. #Docker
  31. docker run cmd.cat/mpstat mpstat

mpstat 命令补充说明:


mpstat 命令主要用于多 CPU 环境下,它显示各个可用 CPU 的状态。这些信息存放在 /proc/stat 文件中。在多 CPUs 系统里,其不但能查看所有 CPU 的平均状况信息,而且能够查看特定 CPU 的信息。

mpstat 命令语法:


  1. mpstat [ options ] [ [ ] ]
  2. Options are:
  3. [ -A ] [ -u ] [ -V ] [ -I { SUM | CPU | SCPU | ALL } ]
  4. [ -P { [,...] | ON | ALL } ]

mpstat 命令选项:


  1. -P:指定CPU编号。

mpstat 命令参数:


  1. 间隔时间:每次报告的间隔时间(秒);
  2. 次数: 显示报告的次数。

mpstat 命令实例:


查看多核 CPU 当前运行的状况,每两秒更新一次,一共更新 5 次:

  1. [root@TestMaster ~]
  2. $ mpstat 2 5
  3.  
  4. Linux 3.10.0-957.10.1.el7.x86_64 (TestMaster) 05/05/2019 _x86_64_ (4 CPU)
  5.  
  6. 11:50:49 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
  7. 11:50:51 AM all 0.25 0.00 0.13 0.00 0.00 0.00 0.00 0.00 0.00 99.62
  8. 11:50:53 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
  9. 11:50:55 AM all 0.13 0.00 0.13 0.00 0.00 0.00 0.00 0.00 0.00 99.75
  10. 11:50:57 AM all 0.12 0.00 0.12 0.00 0.00 0.00 0.00 0.00 0.00 99.75
  11. 11:50:59 AM all 0.13 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.87
  12. Average: all 0.13 0.00 0.08 0.00 0.00 0.00 0.00 0.00 0.00 99.80

说明当 mpstat 不带参数时,输出为从系统启动以来的平均值

  1. %user      internal时间段里,用户态的CPU时间(%),不包含nice值为负进程  (usr/total)*100
  2. %nice      internal时间段里,nice值为负进程的CPU时间(%)   (nice/total)*100
  3. %sys       internal时间段里,内核时间(%)       (system/total)*100
  4. %iowait    internal时间段里,硬盘IO等待时间(%) (iowait/total)*100
  5. %irq         internal时间段里,硬中断时间(%)     (irq/total)*100
  6. %soft       internal时间段里,软中断时间(%)     (softirq/total)*100
  7. %idle       internal时间段里,CPU除去等待磁盘IO操作外的因为任何原因而空闲的时间闲置时间(%) (idle/total)*100
  8.  
  9. 计算公式如下:
  10. total_cur=user+system+nice+idle+iowait+irq+softirq
  11. total_pre=pre_user+ pre_system+ pre_nice+ pre_idle+ pre_iowait+ pre_irq+ pre_softirq
  12. user=user_cur user_pre
  13. total=total_cur-total_pre

其中 _cur 表示当前值,_pre 表示 interval 时间前的值。上表中的所有值可取到两位小数点。

mpstat 命令扩展阅读:




mpstat 命令评论

共收录到 524Linux 命令