首页 / 操作系统 / Linux / Linux系统中Sysstat性能监控工具包中20个实用命令
今天,我们将会通过一些有趣的实例来学习mpstat, pidstat, iostat和sar等工具,这些工具可以帮组我们找出系统中的问题。这些工具都包含了不同的选项,这意味着你可以根据不同的工作使用不同的选项,或者根据你的需求来自定义脚本。我们都知道,系统管理员都会有点懒,他们经常去寻找一些更简单的方法来完成他们的工作。
mpstat - 处理器统计信息
1.不带任何参数的使用mpstat命令将会输出所有CPU的平均统计信息
复制代码代码如下:tecmint@tecmint ~ $ mpstat
Linux 3.11.0-23-generic (tecmint.com) Thursday 04 September 2014_i686_(2 CPU)
12:23:57ISTCPU%usr %nice%sys %iowait%irq %soft%steal%guest%gnice %idle
12:23:57ISTall 37.350.014.722.960.000.070.000.000.00 54.88
2.使用‘-p’ (处理器编号)和‘ALL’参数将会从0开始独立的输出每个CPU的统计信息,0表示第一个cpu。
复制代码代码如下:tecmint@tecmint ~ $ mpstat -P ALL
Linux 3.11.0-23-generic (tecmint.com) Thursday 04 September 2014_i686_(2 CPU)
12:29:26ISTCPU%usr %nice%sys %iowait%irq %soft%steal%guest%gnice %idle
12:29:26ISTall 37.330.014.572.580.000.070.000.000.00 55.44
12:29:26IST0 37.900.014.962.620.000.030.000.000.00 54.48
12:29:26IST1 36.750.014.192.540.000.110.000.000.00 56.40
3.要进行‘N’次,平均每次间隔n秒的输出CPU统计信息,如下所示。
复制代码代码如下:tecmint@tecmint ~ $ mpstat -P ALL 2 5
Linux 3.11.0-23-generic (tecmint.com) Thursday 04 September 2014_i686_(2 CPU)
12:36:21ISTCPU%usr %nice%sys %iowait%irq %soft%steal%guest%gnice %idle
12:36:23ISTall 53.380.002.260.000.000.000.000.000.00 44.36
12:36:23IST0 46.230.001.510.000.000.000.000.000.00 52.26
12:36:23IST1 60.800.003.020.000.000.000.000.000.00 36.18
12:36:23ISTCPU%usr %nice%sys %iowait%irq %soft%steal%guest%gnice %idle
12:36:25ISTall 34.180.002.300.000.000.000.000.000.00 63.52
12:36:25IST0 31.630.001.530.000.000.000.000.000.00 66.84
12:36:25IST1 36.730.002.550.000.000.000.000.000.00 60.71
12:36:25ISTCPU%usr %nice%sys %iowait%irq %soft%steal%guest%gnice %idle
12:36:27ISTall 33.420.005.060.250.000.250.000.000.00 61.01
12:36:27IST0 34.340.004.040.000.000.000.000.000.00 61.62
12:36:27IST1 32.820.006.150.510.000.000.000.000.00 60.51
(LCTT译注: 上面命令中‘2’ 表示每2秒执行一次‘mpstat -P ALL’命令, ‘5’表示共执行5次)
4.使用‘I’参数将会输出每个处理器的中断统计信息
复制代码代码如下:tecmint@tecmint ~ $ mpstat -I
Linux 3.11.0-23-generic (tecmint.com) Thursday 04 September 2014_i686_(2 CPU)
12:39:56ISTCPUintr/s
12:39:56ISTall651.04
12:39:56ISTCPU0/s1/s6/s8/s9/s 12/s 16/s 17/s 20/s 21/s 22/s 23/s 45/s 46/s 47/sNMI/sLOC/sSPU/sPMI/sIWI/sRTR/sRES/sCAL/sTLB/sTRM/sTHR/sMCE/sMCP/sERR/sMIS/s
12:39:56IST076.27 1.73 0.00 0.00 0.42 0.33 0.00 0.0611.46 0.00 0.00 0.01 7.62 1.87 0.05 0.33 182.26 0.00 0.33 3.03 0.0022.66 0.16 5.14 0.00 0.00 0.00 0.00 0.00 0.00
12:39:56IST170.88 1.44 0.00 0.00 0.41 0.33 0.0027.9110.33 0.00 0.00 0.01 7.27 1.79 0.05 0.32 184.11 0.00 0.32 5.17 0.0022.09 0.13 4.73 0.00 0.00 0.00 0.00 0.00 0.00
12:39:56ISTCPU HI/sTIMER/s NET_TX/s NET_RX/sBLOCK/s BLOCK_IOPOLL/sTASKLET/sSCHED/sHRTIMER/sRCU/s
12:39:56IST0 0.00 116.49 0.05 0.27 7.33 0.00 1.2210.44 0.1337.47
12:39:56IST1 0.00 111.65 0.05 0.41 7.07 0.0056.36 9.97 0.1341.38
5.使用‘A’参数将会输出上面提到的所有信息,等同于‘-u -I All -p ALL’。
复制代码代码如下:tecmint@tecmint ~ $ mpstat -A
Linux 3.11.0-23-generic (tecmint.com) Thursday 04 September 2014_i686_(2 CPU)
12:41:39ISTCPU%usr %nice%sys %iowait%irq %soft%steal%guest%gnice %idle
12:41:39ISTall 38.700.014.472.010.000.060.000.000.00 54.76
12:41:39IST0 39.150.014.822.050.000.020.000.000.00 53.95
12:41:39IST1 38.240.014.121.980.000.090.000.000.00 55.57
12:41:39ISTCPUintr/s
12:41:39ISTall651.73
12:41:39IST0173.16
12:41:39IST1225.89
12:41:39ISTCPU0/s1/s6/s8/s9/s 12/s 16/s 17/s 20/s 21/s 22/s 23/s 45/s 46/s 47/sNMI/sLOC/sSPU/sPMI/sIWI/sRTR/sRES/sCAL/sTLB/sTRM/sTHR/sMCE/sMCP/sERR/sMIS/s
12:41:39IST076.04 1.77 0.00 0.00 0.41 0.36 0.00 0.0611.60 0.00 0.00 0.01 7.42 1.83 0.05 0.34 182.89 0.00 0.34 2.97 0.0022.69 0.16 5.22 0.00 0.00 0.00 0.00 0.00 0.00
12:41:39IST170.70 1.48 0.00 0.00 0.40 0.36 0.0027.4710.46 0.00 0.00 0.01 7.08 1.75 0.05 0.32 184.83 0.00 0.32 5.10 0.0022.19 0.13 4.91 0.00 0.00 0.00 0.00 0.00 0.00
12:41:39ISTCPU HI/sTIMER/s NET_TX/s NET_RX/sBLOCK/s BLOCK_IOPOLL/sTASKLET/sSCHED/sHRTIMER/sRCU/s
12:41:39IST0 0.00 116.96 0.05 0.26 7.12 0.00 1.2410.42 0.1236.99
12:41:39IST1 0.00 112.25 0.05 0.40 6.88 0.0055.05 9.93 0.1341.20