Linux CPU实时监控命令mpstat介绍

简介:
1,简介
  mpstat是Multiprocessor  Statistics的缩写,是实时系统监控工具。其报告是CPU的一些统计信息,这些信息存放在/proc/stat文件中。在多CPUs系统里,其不但能查看所有CPU的平均状况信息,而且能够查看特定CPU的信息。mpstat最大的特点是:可以查看多核心cpu中每个计算核心的统计数据;而类似工具vmstat只能查看系统整体cpu情况。
   2,安装
[root@ora10g ~]# mpstat
-bash: mpstat: command not found
[root@ora10g ~]# mount -o loop -t iso9660 /dev/cdrom /mnt/cdrom
[root@ora10g ~]# cd /mnt/cdrom/Server/
[root@ora10g Server]# rpm -ivh sysstat-7.0.2-3.el5.i386.rpm
warning: sysstat-7.0.2-3.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
1:sysstat                ########################################### [100%]
   3,实例
  用法
  mpstat -V  显示mpstat版本信息
  mpstat -P ALL 显示所有CPU信息
  mpstat -P n 显示第n个cup信息,n为数字,计数从0开始
  mpstat n m  每个n秒显示一次cpu信息,连续显示m次,最后显示一个平均值
  mpstat n    每个n秒显示一次cpu信息,连续显示下去
  查看每个cpu核心的详细当前运行状况信息,输出如下:
[root@ora10g ~]# mpstat -P ALL
Linux 2.6.18-194.el5 (ora10g.up.com)    11/05/14
09:13:02     CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
09:13:02     all    0.62    0.01    0.54    3.48    0.00    0.02    0.00   95.32   1039.58
09:13:02       0    0.92    0.01    1.18    8.77    0.01    0.05    0.00   89.06   1030.23
09:13:02       1    0.27    0.00    0.31    1.46    0.00    0.01    0.00   97.96      1.00
....
09:13:02      14    1.12    0.02    0.45    2.99    0.00    0.01    0.00   95.39      7.74
09:13:02      15    0.18    0.00    0.22    0.70    0.00    0.01    0.00   98.90      0.59
  查看多核CPU核心的当前运行状况信息, 每2秒更新一次
  [root@ora10g ~]# mpstat -P ALL 2
  查看某个cpu的使用情况,数值在[0,cpu个数-1]中取值
  [root@ora10g ~]# mpstat -P 2
  Linux 2.6.18-194.el5 (ora10g.up.com)    11/05/14
  10:19:28     CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
  10:19:28       2    0.08    0.00    0.04    0.22    0.00    0.01    0.00   99.64      0.55
  查看多核CPU核心的当前运行状况信息, 每2秒更新一次,显示5次
  [root@ora10g ~]# mpstat -P ALL 2 5
  4,字段含义如下
  英文解释:
  CPU:Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
  %user:Show the percentage of CPU utilization that occurred while executing at the user level (application).
  %nice:Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
  %sys:Show  the  percentage  of CPU utilization that occurred while executing at the system level (kernel). Note that
  this does not include time spent servicing interrupts or softirqs.
  %iowait:Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk  I/O request.
  %irq:Show the percentage of time spent by the CPU or CPUs to service interrupts.
  %soft:Show  the  percentage  of time spent by the CPU or CPUs to service softirqs.  A softirq (software interrupt) is
  one of up to 32 enumerated software interrupts which can run on multiple CPUs at once.
  %steal:Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was  ser-vicing another virtual processor.
  %idle:Show  the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
  intr/s:Show the total number of interrupts received per second by the CPU or CPUs.
  参数解释 从/proc/stat获得数据
  CPU 处理器 ID
  user 在internal时间段里,用户态的CPU时间(%),不包含 nice值为负 进程 (usr/total)*100
  nice 在internal时间段里,nice值为负进程的CPU时间(%)   (nice/total)*100
  system 在internal时间段里,核心时间(%)   (system/total)*100
  iowait 在internal时间段里,硬盘IO等待时间(%) (iowait/total)*100
  irq 在internal时间段里,硬中断时间(%)      (irq/total)*100
  soft 在internal时间段里,软中断时间(%)    (softirq/total)*100
  idle 在internal时间段里,CPU除去等待磁盘IO操作外的因为任何原因而空闲的时间闲置时间(%)(idle/total)*100
  intr/s 在internal时间段里,每秒CPU接收的中断的次数intr/total)*100
  CPU总的工作时间=total_cur=user+system+nice+idle+iowait+irq+softirq
  total_pre=pre_user+ pre_system+ pre_nice+ pre_idle+ pre_iowait+ pre_irq+ pre_softirq
  user=user_cur – user_pre
  total=total_cur-total_pre
  其中_cur 表示当前值,_pre表示interval时间前的值。上表中的所有值可取到两位小数点。

最新内容请见作者的GitHub页:http://qaseven.github.io/
相关文章
|
运维 Linux 虚拟化
Linux 查看 CPU 使用情况
在 Linux 系统中,查看 CPU 使用情况是性能分析和故障排查的重要环节。查看 CPU 使用情况,使用 top 命令或者 htop 命令来查看。
|
缓存 监控 Linux
在Linux中,如何看当前系统有几颗物理CPU和每颗CPU的核数?
在Linux中,如何看当前系统有几颗物理CPU和每颗CPU的核数?
|
Ubuntu Linux 应用服务中间件
Linux使用cpulimit对CPU使用率进行限制
cpulimit是一款简单易用的CPU使用率限制工具,支持对特定程序或整个CPU使用率进行限制。可通过源安装(如`yum`或`apt-get`)或编译安装获取。使用时,可针对程序名、进程号或绝对路径设置CPU占用上限(如`cpulimit -e xmrig -l 60 -b`)。ROOT用户可限制所有进程,普通用户仅限于权限范围内进程。注意,CPU百分比基于实际核心数(单核100%,双核200%,依此类推)。
1735 7
|
存储 缓存 Linux
Linux系统中如何查看CPU信息
本文介绍了查看CPU核心信息的方法,包括使用`lscpu`命令和读取`/proc/cpuinfo`文件。`lscpu`能快速提供逻辑CPU数量、物理核心数、插槽数等基本信息;而`/proc/cpuinfo`则包含更详细的配置数据,如核心ID和处理器编号。此外,还介绍了如何通过`lscpu`和`dmidecode`命令获取CPU型号、制造商及序列号,并解释了CPU频率与缓存大小的相关信息。最后,详细解析了`lscpu`命令输出的各项参数含义,帮助用户更好地理解CPU的具体配置。
1739 8
|
缓存 安全 Linux
Linux系统查看操作系统版本信息、CPU信息、模块信息
在Linux系统中,常用命令可帮助用户查看操作系统版本、CPU信息和模块信息
3672 23
|
缓存 监控 Linux
|
缓存 运维 Linux
深入探索Linux内核:CPU拓扑结构探测
【10月更文挑战第18天】在现代计算机系统中,CPU的拓扑结构对性能优化和资源管理至关重要。了解CPU的核心、线程、NUMA节点等信息,可以帮助开发者和系统管理员更好地调优应用程序和系统配置。本文将深入探讨如何在Linux内核中探测CPU拓扑结构,介绍相关工具和方法。
499 0
|
缓存 Linux 调度
Linux服务器如何查看CPU占用率、内存占用、带宽占用
Linux服务器如何查看CPU占用率、内存占用、带宽占用
10412 0
在Linux中,如何找出占用CPU或内存最多的进程?
在Linux中,如何找出占用CPU或内存最多的进程?