设为首页 收藏本站
查看: 696|回复: 0

[经验分享] Linux性能分析之mpstat&iostat&sar&vmstat

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-6-21 09:19:18 | 显示全部楼层 |阅读模式
安装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 数据库性能问题非常方便。
sarSar以下命令都可以interval count参数
[iyunv@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。
[iyunv@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
[iyunv@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
每秒钟创建的进程数
[iyunv@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)包的总数
[iyunv@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分钟的系统平均负载
[iyunv@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[iyunv@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[iyunv@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.


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-233100-1-1.html 上篇帖子: RedHat 7配置ISCSI服务 下篇帖子: another app is currently hold yum lock问题 Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表