温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux性能分析之mpstat&iostat&sar&vmstat

发布时间:2020-06-13 21:16:48 来源:网络 阅读:843 作者:断情漠 栏目:移动开发

安装sysstat rpm包就有iostatmpstatsarsa的功能,rpm –Uvh sysstat*

mpstat

另一个用于获取 CPU 相关统计信息的有用的命令是 mpstat。下面是一个示例输出:

 

# mpstat -P ALL 5 2

Linux 2.6.9-67.ELsmp (oraclerac1)       12/20/2008

 

10:42:38 PM  CPU  %user   %nice %system %iowait    %irq  %soft   %idle    intr/s

10:42:43 PM  all   6.89    0.00   44.76   0.10    0.10    0.10  48.05   1121.60

10:42:43 PM    0   9.20    0.00   49.00   0.00    0.00    0.20  41.60    413.00

10:42:43 PM    1   4.60    0.00   40.60   0.00    0.20    0.20  54.60    708.40

 

10:42:43 PM  CPU  %user   %nice %system %iowait    %irq  %soft   %idle    intr/s

10:42:48 PM  all   7.60    0.00   45.30   0.30    0.00    0.10  46.70   1195.01

10:42:48 PM    0   4.19    0.00    2.20   0.40    0.00    0.00  93.21   1034.53

10:42:48 PM    1  10.78    0.00   88.22   0.40    0.00    0.00   0.20    160.48

 

Average:     CPU  %user   %nice %system %iowait    %irq  %soft   %idle    intr/s

Average:     all   7.25    0.00   45.03   0.20    0.05    0.10  47.38   1158.34

Average:       0   6.69    0.00   25.57   0.20    0.00    0.10  67.43    724.08

Average:       1   7.69    0.00   64.44   0.20    0.10    0.10  27.37    434.17

 

它显示了系统中 CPU 的各种统计信息。–P ALL 选项指示该命令显示所有 CPU 的统计信息,而不只是特定 CPU 的统计信息。参数 5 2 指示该命令每隔 5 秒运行一次,共运行 2次。以上输出首先显示了所有 CPU 的合计指标,然后显示了每个 CPU 各自的指标。最后,在结尾处显示所有 CPU 的平均值。

 

让我们看一看这些列值的含义:

 

%user    表示处理用户进程所使用 CPU 的百分比。用户进程是用于应用程序(如 Oracle 数据库)的非内核进程。在本示例输出中,用户 CPU 百分比非常低。

%nice    表示使用 nice 命令对进程进行降级时 CPU 的百分比。在之前的部分中已经对 nice 命令进行了介绍。简单来说,nice 命令更改进程的优先级。

%system  表示内核进程使用的 CPU 百分比

%iowait  表示等待进行 I/O 所使用的 CPU 时间百分比

%irq     表示用于处理系统中断的 CPU 百分比

%soft    表示用于软件中断的 CPU 百分比

%idle    显示 CPU 的空闲时间

%intr/s   显示每秒 CPU 接收的中断总数

当您拥有前面所述的 vmstat 时,您可能想知道 mpstat 命令的作用。差别很大:mpstat 可以显示每个处理器的统计,而vmstat 显示所有处理器的统计。因此,编写糟糕的应用程序(不使用多线程体系结构)可能会运行在一个多处理器机器上,而不使用所有处理器。从而导致一个 CPU 过载,而其他 CPU 却很空闲。通过 mpstat 可以轻松诊断这些类型的问题。

针对 Oracle 用户的用法   vmstat 相似,mpstat 命令还产生与 CPU 有关的统计信息,因此所有与CPU 问题有关的讨论也都适用于 mpstat

当您看到较低的 %idle 数字时,您知道出现了 CPU 不足的问题。当您看到较高的 %iowait 数字时,您知道在当前负载下 I/O 子系统出现了某些问题。该信息对于解决 Oracle 数据库性能问题非常方便。

sar

Sar以下命令都可以interval count参数

[root@daidai ~]# sar -u 2 2

Linux 2.6.18-194.el5 (daidai.com)       06/20/2016

 

11:14:10 AM       CPU    %user     %nice   %system  %iowait    %steal     %idle

11:14:12 AM       all     0.25      0.00      0.00     0.25      0.00     99.49

11:14:14 AM       all     0.00      0.50      0.76     0.00      0.00     98.74

Average:          all      0.13     0.25      0.38      0.13     0.00     99.12

CPU    all 表示统计信息为所有 CPU 的平均值。

%user   显示在用户级别(application)运行使用 CPU 总时间的百分比。

%nice   显示在用户级别,用于nice操作,所占用 CPU 总时间的百分比。

%system 在核心级别(kernel)运行所使用 CPU 总时间的百分比。

%iowait 显示用于等待I/O操作占用 CPU 总时间的百分比。

%steal  管理程序(hypervisor)为另一个虚拟进程提供服务而等待虚拟 CPU 的百分比。

%idle   显示 CPU 空闲时间占用 CPU 总时间的百分比。

tips

%iowait 的值过高,表示硬盘存在I/O瓶颈

%idle 的值高但系统响应慢时,有可能是 CPU 等待分配内存,此时应加大内存容量

%idle 的值持续低于 10,则系统的 CPU 处理能力相对较低,表明系统中最需要解决的资源是 CPU

[root@daidai ~]# sar -b 2 3

Linux 2.6.18-194.el5 (daidai.com)       06/20/2016

 

11:31:08 AM       tps     rtps      wtps   bread/s  bwrtn/s

11:31:10 AM      3.03     0.00      3.03      0.00   129.29

11:31:12 AM      3.03     0.00      3.03      0.00    64.65

11:31:14 AM      3.05     0.00      3.05      0.00    64.97

Average:         3.04      0.00     3.04      0.00     86.34

tps    每秒钟物理设备的 I/O 传输总量

rtps   每秒钟从物理设备读入的数据总量

wtps   每秒钟向物理设备写入的数据总量

bread/s 每秒钟从物理设备读入的数据量,单位为 /s

bwrtn/s 每秒钟向物理设备写入的数据量,单位为 /s

[root@daidai ~]# sar -c

Linux 2.6.18-194.el5 (daidai.com)       06/20/2016

 

09:50:01 AM    proc/s

10:00:01 AM      0.38

10:10:01 AM      0.30

10:20:01 AM      0.30

10:30:01 AM      0.45

10:40:01 AM      0.30

11:20:01 AM      0.79

11:30:01 AM      0.28

Average:         0.43

每秒钟创建的进程数

[root@daidai ~]# sar -n DEV 1 2

Linux 2.6.18-194.el5 (daidai.com)       06/20/2016

 

11:39:34 AM     IFACE  rxpck/s   txpck/s   rxbyt/s  txbyt/s   rxcmp/s   txcmp/s rxmcst/s

11:39:35 AM        lo     0.00      0.00      0.00     0.00      0.00      0.00     0.00

11:39:35 AM      eth0     0.00      0.00      0.00     0.00      0.00      0.00     0.00

11:39:35 AM      sit0     0.00      0.00      0.00     0.00      0.00      0.00     0.00

 

11:39:35 AM     IFACE  rxpck/s   txpck/s   rxbyt/s  txbyt/s   rxcmp/s   txcmp/s rxmcst/s

11:39:36 AM        lo     2.04      2.04    102.04   102.04      0.00      0.00     0.00

11:39:36 AM      eth0     3.06      5.10    183.67   867.35      0.00      0.00     0.00

11:39:36 AM      sit0     0.00      0.00      0.00     0.00      0.00      0.00     0.00

 

Average:        IFACE  rxpck/s   txpck/s   rxbyt/s  txbyt/s   rxcmp/s   txcmp/s rxmcst/s

Average:           lo      1.02     1.02     50.76     50.76     0.00      0.00      0.00

Average:         eth0      1.52     2.54     91.37    431.47     0.00      0.00      0.00

Average:         sit0      0.00     0.00      0.00      0.00     0.00      0.00      0.00

IFACE      网络设备名

rxpck/s    每秒接收的包总数

txpck/s    每秒传输的包总数

rxbyt/s    每秒接收的字节(byte)总数

txbyt/s    每秒传输的字节(byte)总数

rxcmp/s    每秒接收压缩包的总数

txcmp/s   每秒传输压缩包的总数

rxmcst/s   每秒接收的多播(multicast)包的总数

[root@daidai ~]# sar -q 1 3

Linux 2.6.18-194.el5 (daidai.com)       06/20/2016

 

11:42:54 AM   runq-sz plist-sz   ldavg-1   ldavg-5 ldavg-15

11:42:55 AM         0      184      0.02      0.02     0.00

11:42:56 AM         0      184      0.02      0.02     0.00

11:42:57 AM         0      184      0.02      0.02     0.00

Average:            0       184     0.02      0.02      0.00

runq-sz  运行队列的长度(等待运行的进程数)

plist-sz   进程列表中进程(processes)和线程(threads)的数量

ldavg-1  最后1分钟的系统平均负载(System load average

ldavg-5  过去5分钟的系统平均负载

ldavg-15  过去15分钟的系统平均负载

[root@daidai ~]# sar -r

Linux 2.6.18-194.el5 (daidai.com)       06/20/2016

 

09:50:01 AM kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused kbswpcad

10:00:01 AM   1067600  3869580     78.38    195616  3249408  10482404         0     0.00         0

10:10:01 AM   1068624  3868556     78.36    195616  3249500  10482404         0     0.00         0

10:20:01 AM   1069492  3867688     78.34    195616  3249572  10482404         0     0.00         0

10:30:01 AM   1079024  3858156     78.14    195616  3249588  10482404         0     0.00         0

10:40:01 AM   1079676  3857504     78.13    195616  3249616  10482404         0     0.00         0

11:20:01 AM   1083792  3853388     78.05    195616  3249952  10482404         0     0.00         0

11:30:01 AM   1083420  3853760     78.06    195616  3249984  10482404         0     0.00         0

11:40:01 AM   1084164  3853016     78.04    195616  3250008  10482404         0     0.00         0

Average:      1076974  3860206     78.19    195616  3249704  10482404         0     0.00         0

kbmemfree   Amountof free memory available in kilobytes.

kbmemused  Amount of used memory in kilobytes. This doesnot take into account memory used by the kernel itself.

%memused   Percentage of used memory.

kbbuffers     Amount of memory used as buffers by thekernel in kilobytes.

kbcached     Amount of memory used to cache data by thekernel in kilobytes.

kbswpfree    Amount of free swap space in kilobytes.

kbswpused    Amount of used swap space in kilobytes.

%swpused    Percentage of used swap space.

kbswpcad     Amount of cached swap memory inkilobytes.  This is memory that once was swappedout, is swapped back in but still also is in the swap area (if memory is neededit doesn’t need to be swapped out again because it is already in the swap area.This saves I/O).

iostat

[root@daidai ~]# iostat 1 3

Linux 2.6.18-194.el5 (daidai.com)       06/20/2016

 

avg-cpu: %user   %nice %system %iowait  %steal  %idle

           0.23    0.02   0.43    0.11    0.00  99.22

 

Device:            tps   Blk_read/s  Blk_wrtn/s   Blk_read   Blk_wrtn

sda               3.15        15.25        60.92   3462295   13828032

sda1              3.15        15.24        60.92   3460258   13828032

sda2              0.00         0.01         0.00       1613          0

sr0               0.00         0.01         0.00       1644          0

 

avg-cpu: %user   %nice %system %iowait  %steal  %idle

           0.51    0.00   0.51    0.00    0.00  98.98

 

Device:            tps   Blk_read/s  Blk_wrtn/s   Blk_read   Blk_wrtn

sda               0.00         0.00         0.00          0          0

sda1              0.00         0.00        0.00          0          0

sda2              0.00         0.00         0.00          0          0

sr0               0.00         0.00         0.00          0          0

 

avg-cpu: %user   %nice %system %iowait  %steal  %idle

           0.00    0.00   0.51    0.00    0.00  99.49

 

Device:            tps   Blk_read/s  Blk_wrtn/s   Blk_read   Blk_wrtn

sda               3.00         0.00        64.00          0         64

sda1              3.00         0.00        64.00          0         64

sda2              0.00         0.00         0.00          0          0

sr0               0.00         0.00         0.00          0          0

vmstat

[root@daidai ~]# vmstat 1 5

procs -----------memory-------------swap-- -----io---- --system-- -----cpu------

 r b   swpd   free  buff  cache   si  so    bi    bo  in   cs us sy id wa st

 0 0      0 1083368 1957003250136    0    0    4    16   24  41  0  0 99 0  0

 0 0      0 1083368 1957003250136    0    0    0    40  998 205  1  1 99 0  0

 0  0      0 1083368 195700 3250136    0   0     0    32 998  221  0  298  1 0

 0 0      0 1089088 1957003250136    0    0    0     0  998 218  0  1 99 0  0

 0 0      0 1089088 1957003250136    0    0    0     0 1004  191 0  0 100  0  0

Procs

r: The number of processes waiting forrun time.

b: The number of processes inuninterruptible sleep.

 

Memory

swpd: the amount of virtual memory used.

free: the amount of idle memory.

buff: the amount of memory used asbuffers.

cache: the amount of memory used ascache.

inact: the amount of inactive memory.(-a option)

active: the amount of active memory. (-aoption)

 

Swap

si: Amount of memory swapped in fromdisk (/s).

so: Amount of memory swapped to disk(/s).

 

IO

bi: Blocks received from a block device (blocks/s).

bo: Blocks sent to a block device(blocks/s).

 

System

in: The number of interrupts per second,including the clock.

cs: The number of context switches persecond.

 

CPU

These are percentages of total CPU time.

us: Time spent running non-kernel code.(user time, including nice time)

sy: Time spent running kernel code.(system time)

id: Time spent idle. Prior to Linux2.5.41, this includes IO-wait time.

wa: Time spent waiting for IO. Prior toLinux 2.5.41, included in idle.

st: Time stolen from a virtual machine.Prior to Linux 2.6.11, unknown.


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI