Linux - 查看CPU使用率命令mpstat

简介

想在imx6q上定时查看CPU使用率,发现 命令mpstat可以直接使用,不需要额外安装

 

使用

mpstat的基本用法

mpstat的全称为Multiprocessor Statistics,是一款常用的多核CPU性能分析工具,用来实时查询每个CPU的性能指标,以及所有CPU的平均指标。

这个命令Linux缺省没有安装,它是Linux性能工具集sysstat中的一个工具,所以我们要装上sysstat,安装方法随不同的系统略有不同,自行百度,我列出CentOS和Ubuntu的

[root@localhost ~]# yum -y install sysstat  # CentOS
[root@localhost ~]# apt install sysstat     # ubuntu

 

mpstat的语法:

mpstat    [-P {|ALL}]     [internal    [count]]

参数解释:

  • -P: 指定要监控哪个CPU,范围是[0 ~ n-1], ALL表示监控所有CPU都监控
  • internal: 相邻两次采样的间隔时间
  • count: 采样次数。

 

示例

[root@localhost ~]# mpstat -P ALL 3 2   # –P ALL 选项指示该命令显示所有 CPU 的统计信息
										# 3 2  该指令每隔3秒运行一次,总共运行两次
Linux 2.6.32-642.el6.x86_64 (localhost.localdomain) 2020年04月11日 _x86_64_	(2 CPU)
#第一部分
11时01分42秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
11时01分45秒  all    0.51    0.00    0.34    0.00    0.00    0.17    0.00    0.00   98.99
11时01分45秒    0    0.68    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.32
11时01分45秒    1    0.34    0.00    0.34    0.00    0.00    0.34    0.00    0.00   98.98

11时01分45秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
11时01分48秒  all    0.17    0.00    1.19    0.00    0.00    0.17    0.00    0.00   98.47
11时01分48秒    0    0.00    0.00    1.03    0.00    0.00    0.00    0.00    0.00   98.97
11时01分48秒    1    0.34    0.00    1.35    0.00    0.00    0.34    0.00    0.00   97.98
#第二部分
平均时间:  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
平均时间:  all    0.34    0.00    0.76    0.00    0.00    0.17    0.00    0.00   98.73
平均时间:    0    0.34    0.00    0.51    0.00    0.00    0.00    0.00    0.00   99.15
平均时间:    1    0.34    0.00    0.84    0.00    0.00    0.34    0.00    0.00   98.48

第一部分:输出首先显示了所有 CPU 的合计指标,然后显示了每个 CPU 各项的指标。

第二部分:在结尾处显示所有 CPU 的平均值。

各列的含义:

%user: 表示用户态所使用 CPU 的百分比。
%nice: 表示使用 nice 命令对进程进行降级时 CPU 的百分比。
%sys: 表示内核进程使用的 CPU 百分比。
%iowait: 表示等待进行 I/O 所使用的 CPU 时间百分比。
%irq: 表示用于处理系统中断的 CPU 百分比。
%soft: 表示用于软件中断的 CPU 百分比。
%steal:虚拟机强制CPU等待的时间百分比。
%guest: 虚拟机占用CPU时间的百分比。
%idle: CPU 的空闲时间的百分比。

 

 

参考连接:https://www.cnblogs.com/daanzhijia/p/14420835.html

posted @ 2024-08-02 14:41  Citrusliu  阅读(5)  评论(0编辑  收藏  举报