CPU 使用率:top 和 mpstat 显示不同的结果

Mah*_*esh 3 server nginx php-fpm

topmpstat显示出不同的结果。

top:

%Cpu(s): 10.9 us,  3.1 sy,  0.0 ni, 85.2 id,  0.2 wa,  0.0 hi,  0.7 si,  0.0 st

31426 www-data  20   0  309088  21276  14600 S  22.3  0.1   0:07.36 php-fpm: pool www
31431 www-data  20   0  308980  21232  14568 S  22.3  0.1   0:01.69 php-fpm: pool www
31423 www-data  20   0  308992  21376  14664 S  21.6  0.1   0:08.38 php-fpm: pool www
31437 www-data  20   0  308988  21224  14568 R  20.9  0.1   0:00.66 php-fpm: pool www
Run Code Online (Sandbox Code Playgroud)

mpstat

04:05:29 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:05:29 PM  all    1.06    0.00    0.29    0.02    0.00    0.06    0.00    0.00    0.00   98.57
04:05:29 PM    0    0.81    0.00    0.32    0.03    0.00    0.00    0.00    0.00    0.00   98.84
04:05:29 PM    1    1.40    0.00    0.37    0.02    0.00    0.07    0.00    0.00    0.00   98.14
04:05:29 PM    2    1.39    0.00    0.36    0.02    0.00    0.07    0.00    0.00    0.00   98.16
04:05:29 PM    3    1.35    0.00    0.35    0.02    0.00    0.07    0.00    0.00    0.00   98.21
04:05:29 PM    4    0.98    0.00    0.25    0.01    0.00    0.08    0.00    0.00    0.00   98.68
04:05:29 PM    5    0.86    0.00    0.22    0.01    0.00    0.06    0.00    0.00    0.00   98.85
04:05:29 PM    6    0.81    0.00    0.21    0.02    0.00    0.06    0.00    0.00    0.00   98.90
04:05:29 PM    7    0.87    0.00    0.22    0.02    0.00    0.06    0.00    0.00    0.00   98.83
Run Code Online (Sandbox Code Playgroud)

服务器已经超载了吗?

muc*_*lux 5

top:

100% 表示 1 个 CPU 已完全使用。因此,您看到的 php-fpm 是 8 个 CPU 中的 1 个 CPU 的 87.1%,即不到总 CPU 能力的 11%。

mpstat:

如果您没有给 mpstat 指定时间间隔,它会提供自启动以来的平均 CPU 利用率。 mpstat -P ALL 2 5为您提供 2 秒间隔的 5 个结果。