接前一篇文章:Linux性能优化工具系列详解(2)
本系列内容参考:
极客时间 ------ 倪朋飞 《Linux 性能优化实战》
特此致谢!
系列工具
前两回讲解了性能优化系列工具的第1个 ------ uptime。本回讲解第2个命令 ------ mpstat。
2. mpstat
(1)概述
mpstat是Linux系统中sysstat工具包 的核心组件,用于实时监控多核CPU各核心的详细利用率及中断统计,支持按核心拆分数据以定位负载均衡瓶颈。
mpstat命令主要用于多CPU环境下,它显示各个可用CPU的状态。这些信息存放在/proc/stat文件中。在多CPUs系统里,其不但能查看所有CPU的平均状况信息,而且能够查看特定CPU的信息。
(2)详情
注:
既然mpstat隶属于sysstat工具包,那么要使用mpstat命令,需要首先下载sysstat工具包。在笔者的Ubuntu虚拟机中,通过apt命令下载syastat工具包,实际命令及结果如下:
bash
$ sudo apt install sysstat
[sudo] password for ph:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
isag
The following NEW packages will be installed:
sysstat
0 upgraded, 1 newly installed, 0 to remove and 224 not upgraded.
Need to get 487 kB of archives.
After this operation, 1,507 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 sysstat amd64 12.5.2-2ubuntu0.2 [487 kB]
Fetched 487 kB in 0s (1,345 kB/s)
Preconfiguring packages ...
Selecting previously unselected package sysstat.
(Reading database ... 268580 files and directories currently installed.)
Preparing to unpack .../sysstat_12.5.2-2ubuntu0.2_amd64.deb ...
Unpacking sysstat (12.5.2-2ubuntu0.2) ...
Setting up sysstat (12.5.2-2ubuntu0.2) ...
Creating config file /etc/default/sysstat with new version
update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-collect.timer → /lib/systemd/system/sysstat-collect.timer.
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-summary.timer → /lib/systemd/system/sysstat-summary.timer.
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service.
Processing triggers for man-db (2.10.2-1) ...
ph@ph-virtual-machine:~$
只有下载完sysstat工具包之后,man mpstat命令才有内容。
NAME
mpstat - Report processors related statistics.
名称
mpstat ------ 报告处理器相关统计数据。
SYNOPSIS
mpstat -A --dec={ 0 \| 1 \| 2 } -n -u -T -V -I { keyword\[,... | ALL } ] -N { node_list \| ALL } -o JSON -P { cpu_list \| ALL } interval \[ count ]
简介
mpstat -A --dec={ 0 \| 1 \| 2 } -n -u -T -V -I { keyword\[,... | ALL } ] -N { node_list \| ALL } -o JSON -P { cpu_list \| ALL } interval \[ count ]
语法
mpstat 选项 参数
DESCRIPTION
The mpstat command writes to standard output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used on both SMP and UP machines, but in the latter, only global average activities will be printed. If no activity has been selected, then the default report is the CPU utilization report.
The interval parameter specifies the amount of time in seconds between each report. A value of 0 (or no parameters at all) indicates that processors statistics are to be reported for the time since system startup (boot). The count parameter can be specified in conjunction with the interval parameter if this one is not set to zero. The value of count determines the number of reports generated at interval seconds apart. If the interval parameter is specified without the count parameter, the mpstat command generates reports continuously.
描述
mpstat命令将每个可用处理器的活动信息输出到标准输出,其中处理器0为第一个处理器。同时还会报告所有处理器的全局平均活动情况。该命令适用于SMP和UP机器,但在UP机器上仅会打印全局平均活动信息。若未选择特定活动,则默认输出CPU利用率报告。
interval参数指定每个报告之间的时间量(秒)。值0(或根本没有参数)表示要报告自系统启动(引导)以来的处理器统计信息。如果计数参数未设置为零,则可以将其与间隔参数一起指定。计数值决定了以秒为间隔生成的报告数量。如果指定了间隔参数而没有指定计数参数,则mpstat命令会连续生成报告。
更多内容请看下回。