本帖最后由 郑全 于 2026-8-8 11:25 编辑
比如我们已经拿到了一份SAR收集的数据,如何分析系统过去存在的问题,比如,想看
系统的最高进程数量是多少?
哪台设备拥有最高写 I/O 速率? 在单一网卡上持续最长时间的突发流量是从监控开始的多少分钟发生的?
要完整这个,需要使用sar 工具来完成。
sar 属于 sysstat 工具集,Linux 全能性能采集工具,支持实时监控 + 历史日志回放,覆盖 CPU、内存、磁盘 IO、网络、负载、上下文切换。
所以,要用sar ,首先要安装 sysstat
[root@servera test]# yum install sysstat
不清楚如何用,可以看看帮助
man sar
对于第一个问题,查看系统最高进程数量是多少?
sar 有很多选项,选择哪个呢?
先看看帮助:
[root@servera test]# sar --help
Usage: sar [ options ] [ <interval> [ <count> ] ]
Main options and reports (report name between square brackets):
-B Paging statistics [A_PAGE]
-b I/O and transfer rate statistics [A_IO]
-d Block devices statistics [A_DISK]
-F [ MOUNT ]
Filesystems statistics [A_FS]
-H Hugepages utilization statistics [A_HUGE]
-I { <int_list> | SUM | ALL }
Interrupts statistics [A_IRQ]
-m { <keyword> [,...] | ALL }
Power management statistics [A_PWR_...]
Keywords are:
CPU CPU instantaneous clock frequency
FAN Fans speed
FREQ CPU average clock frequency
IN Voltage inputs
TEMP Devices temperature
USB USB devices plugged into the system
-n { <keyword> [,...] | ALL }
Network statistics [A_NET_...]
Keywords are:
DEV Network interfaces
EDEV Network interfaces (errors)
NFS NFS client
NFSD NFS server
SOCK Sockets (v4)
IP IP traffic (v4)
EIP IP traffic (v4) (errors)
ICMP ICMP traffic (v4)
EICMP ICMP traffic (v4) (errors)
TCP TCP traffic (v4)
ETCP TCP traffic (v4) (errors)
UDP UDP traffic (v4)
SOCK6 Sockets (v6)
IP6 IP traffic (v6)
EIP6 IP traffic (v6) (errors)
ICMP6 ICMP traffic (v6)
EICMP6 ICMP traffic (v6) (errors)
UDP6 UDP traffic (v6)
FC Fibre channel HBAs
SOFT Software-based network processing
-q Queue length and load average statistics [A_QUEUE]
-r [ ALL ]
Memory utilization statistics [A_MEMORY]
-S Swap space utilization statistics [A_MEMORY]
-u [ ALL ]
CPU utilization statistics [A_CPU]
-v Kernel tables statistics [A_KTABLES]
-W Swapping statistics [A_SWAP]
-w Task creation and system switching statistics [A_PCSW]
-y TTY devices statistics [A_SERIAL]
通过这个帮助,发现有一个参数,-q
-q Queue length and load average statistics [A_QUEUE]
我们看最大进程,应该就是这个了,看队列和负载,
进一步查看 -q 有哪些信息:
-q Report queue length and load averages. The following values are displayed:
runq-sz
Run queue length (number of tasks waiting for run time).
plist-sz
Number of tasks in the task list.
ldavg-1
System load average for the last minute. The load average is calculated as the average number of
runnable or running tasks (R state), and the number of tasks in uninterruptible sleep (D state) over
the specified interval.
ldavg-5
System load average for the past 5 minutes.
ldavg-15
System load average for the past 15 minutes.
blocked
Number of tasks currently blocked, waiting for I/O to complete.
里面正好有这个 plist-sz ,就是进程数量
我们使用收集数据,看看情况
[root@servera test]# sar -q -f sar.data |head -n 10
Linux 3.10.0-123.el7.x86_64 (localhost.localdomain) 12/29/2014 _x86_64_ (4 CPU)
02:00:27 PM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
02:00:32 PM 0 354 0.00 0.29 0.46 0
02:00:37 PM 0 355 0.00 0.28 0.45 0
02:00:42 PM 0 355 0.00 0.28 0.45 0
02:00:47 PM 0 355 0.00 0.27 0.45 0
02:00:52 PM 0 355 0.00 0.27 0.45 0
02:00:57 PM 0 355 0.00 0.27 0.44 0
02:01:02 PM 0 355 0.00 0.26 0.44 0
正好第四列,就是 进程信息,如何找最大值呢
我们可以通过以下命令来完成:
[root@servera test]# sar -q -f sar.data |sort -nrk 4|head -10
02:35:13 PM 0 807 0.02 0.19 0.65 0
02:35:08 PM 0 802 0.02 0.19 0.65 0
02:35:03 PM 0 797 0.02 0.19 0.65 0
02:34:58 PM 1 792 0.02 0.20 0.66 0
02:34:53 PM 0 787 0.02 0.20 0.66 0
02:34:48 PM 0 782 0.02 0.20 0.66 0
02:34:43 PM 0 777 0.03 0.21 0.67 0
02:34:38 PM 0 772 0.03 0.21 0.67 0
02:34:33 PM 0 767 0.03 0.21 0.67 0
02:34:28 PM 0 762 0.03 0.22 0.68 0
我们可以看到,最高进程数,就是 807 了,
当然,如果,我们只是想看这一列呢,可以使用以下命令:
[root@servera test]# sar -q -f sar.data |awk '{ print $4}'|sort -nr|head -1
807
具体 awk,sort ,head 如何用,ai上有很多,这里就不展开。
第二个问题,哪台设备拥有最高写 I/O 速率?
要看设备的最高写,应该使用哪个选项呢?
[root@servera test]# sar --help
Usage: sar [ options ] [ <interval> [ <count> ] ]
Main options and reports (report name between square brackets):
-B Paging statistics [A_PAGE]
-b I/O and transfer rate statistics [A_IO]
-d Block devices statistics [A_DISK]
-F [ MOUNT ]
Filesystems statistics [A_FS]
-H Hugepages utilization statistics [A_HUGE]
。。。
通过帮助,发现,这个-d 选项,正好是 磁盘设备,我们可以先看看
man sar
-d Report activity for each block device. When data are displayed, the device specification devM-n is generally
used (DEV column). M is the major number of the device and n its minor number. Device names may also be
pretty-printed if option -p is used or persistent device names can be printed if option -j is used (see
below). Note that disk activity depends on sadc options -S DISK and -S XDISK to be collected. The following
values are displayed:
tps
Total number of transfers per second that were issued to physical devices. A transfer is an I/O
request to a physical device. Multiple logical requests can be combined into a single I/O request to
the device. A transfer is of indeterminate size.
rkB/s
Number of kilobytes read from the device per second.
wkB/s
Number of kilobytes written to the device per second.
areq-sz
The average size (in kilobytes) of the I/O requests that were issued to the device.
Note: In previous versions, this field was known as avgrq-sz and was expressed in sectors.
aqu-sz
The average queue length of the requests that were issued to the device.
Note: In previous versions, this field was known as avgqu-sz.
await
The average time (in milliseconds) for I/O requests issued to the device to be served. This includes
the time spent by the requests in queue and the time spent servicing them.
svctm
The average service time (in milliseconds) for I/O requests that were issued to the device. Warning!
Do not trust this field any more. This field will be removed in a future sysstat version.
%util
Percentage of elapsed time during which I/O requests were issued to the device (bandwidth utilization
for the device). Device saturation occurs when this value is close to 100% for devices serving
...
这里看到,如果要看sda,sdb,等等,需要带上 -p
[root@servera test]# sar -dp -f sar.data |head -10
Linux 3.10.0-123.el7.x86_64 (localhost.localdomain) 12/29/2014 _x86_64_ (4 CPU)
02:00:27 PM DEV tps rkB/s wkB/s areq-sz aqu-sz await svctm %util
02:00:32 PM sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:32 PM dev253-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:32 PM dev253-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:32 PM sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:32 PM dev253-2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:32 PM sdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:37 PM sda 0.60 0.00 2.40 4.00 0.00 0.00 0.00 0.00
第六列,正好就是写
[root@servera test]# sar -dp -f sar.data |sort -nrk 6|head -10
02:10:33 PM sdb 180.00 0.00 91189.60 506.61 105.42 587.26 4.46 80.32
02:06:38 PM sdb 179.00 0.00 90709.60 506.76 105.66 590.27 4.47 80.10
02:43:28 PM sdc 178.60 0.00 90700.80 507.84 100.77 563.46 4.77 85.16
02:40:33 PM sdc 178.00 0.00 90435.20 508.06 100.26 561.87 4.95 88.18
02:13:48 PM sdc 178.20 0.00 90342.40 506.97 101.91 570.87 5.19 92.46
02:08:18 PM sdb 177.20 0.00 89913.60 507.41 104.28 581.84 4.51 79.88
02:15:28 PM sdc 174.60 0.80 88624.80 507.59 95.18 544.31 4.62 80.62
02:38:48 PM sdc 172.20 0.00 87664.80 509.09 106.77 559.40 4.55 78.40
02:17:08 PM sdc 172.20 0.00 87584.00 508.62 98.49 560.26 4.50 77.44
02:39:23 PM sdc 171.40 0.00 87280.00 509.22 96.49 560.06 5.05 86.58
最高写,就是 91189.60
只想看这一列,也行
[root@servera test]# sar -dp -f sar.data |awk '{ print $6 }'|sort -nr|head -1
91189.60
第三个题呢? 在单一网卡上持续最长时间的突发流量是从监控开始的多少分钟发生的?
这个看流量,应该是网络吧,看看帮助
[root@servera test]# sar --help|grep -i net -C 5
FREQ CPU average clock frequency
IN Voltage inputs
TEMP Devices temperature
USB USB devices plugged into the system
-n { <keyword> [,...] | ALL }
Network statistics [A_NET_...]
Keywords are:
DEV Network interfaces
EDEV Network interfaces (errors)
NFS NFS client
NFSD NFS server
SOCK Sockets (v4)
IP IP traffic (v4)
EIP IP traffic (v4) (errors)
--
EIP6 IP traffic (v6) (errors)
ICMP6 ICMP traffic (v6)
EICMP6 ICMP traffic (v6) (errors)
UDP6 UDP traffic (v6)
FC Fibre channel HBAs
SOFT Software-based network processing
-q Queue length and load average statistics [A_QUEUE]
-r [ ALL ]
Memory utilization statistics [A_MEMORY]
-S Swap space utilization statistics [A_MEMORY]
-u [ ALL ]
就是选择 -n ,带上 DEV,就有网卡了
man sar -n
-n { keyword [,...] | ALL }
Report network statistics.
Possible keywords are DEV, EDEV, FC, ICMP, EICMP, ICMP6, EICMP6, IP, EIP, IP6, EIP6, NFS, NFSD, SOCK, SOCK6,
SOFT, TCP, ETCP, UDP and UDP6.
With the DEV keyword, statistics from the network devices are reported. The following values are displayed:
IFACE
Name of the network interface for which statistics are reported.
rxpck/s
Total number of packets received per second.
txpck/s
Total number of packets transmitted per second.
rxkB/s
Total number of kilobytes received per second.
txkB/s
Total number of kilobytes transmitted per second.
rxcmp/s
Number of compressed packets received per second (for cslip etc.).
txcmp/s
Number of compressed packets transmitted per second.
rxmcst/s
Number of multicast packets received per second.
%ifutil
...
[root@servera test]# sar -n DEV -f sar.data |head -10
Linux 3.10.0-123.el7.x86_64 (localhost.localdomain) 12/29/2014 _x86_64_ (4 CPU)
02:00:27 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
02:00:32 PM eth0 0.20 0.40 0.02 0.04 0.00 0.00 0.00 0.00
02:00:32 PM eth1 0.20 0.40 0.02 0.04 0.00 0.00 0.00 0.00
02:00:32 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:37 PM eth0 0.40 0.60 0.04 0.09 0.00 0.00 0.00 0.00
02:00:37 PM eth1 0.20 0.40 0.02 0.04 0.00 0.00 0.00 0.00
02:00:37 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:00:42 PM eth0 0.40 0.60 0.04 0.07 0.00 0.00 0.00 0.00
rxpck/s 每秒接收到的包
[root@servera test]# sar -n DEV -f sar.data |sort -nrk 4|head -20
02:08:18 PM eth1 22265.60 68059.00 1547.03 95642.32 0.00 0.00 0.00 0.00
02:10:33 PM eth1 22112.60 68220.40 1536.43 96148.16 0.00 0.00 0.00 0.00
02:09:58 PM eth1 19547.20 60219.40 1358.53 84843.33 0.00 0.00 0.00 0.00
02:06:38 PM eth1 19228.20 67956.80 1339.44 95886.63 0.00 0.00 0.00 0.00
02:08:53 PM eth1 18895.40 58221.00 1312.88 82024.82 0.00 0.00 0.00 0.00
02:07:13 PM eth1 16386.80 50546.40 1138.64 70990.08 0.00 0.00 0.00 0.00
02:07:43 PM eth1 14174.80 43442.80 985.06 61274.04 0.00 0.00 0.00 0.00
02:06:03 PM eth1 14060.60 49946.40 979.80 70534.26 0.00 0.00 0.00 0.00
02:09:23 PM eth1 11534.80 35305.20 801.54 49867.00 0.00 0.00 0.00 0.00
02:09:28 PM eth1 11038.20 33218.60 766.71 46637.77 0.00 0.00 0.00 0.00
02:07:48 PM eth1 8311.60 25102.00 577.32 35157.07 0.00 0.00 0.00 0.00
02:13:48 PM eth0 7003.80 66711.40 476.36 95171.59 0.00 0.00 0.00 0.00
02:40:33 PM eth0 6911.20 66712.60 470.41 95265.01 0.00 0.00 0.00 0.00
02:15:28 PM eth0 6790.00 65284.60 462.88 93351.94 0.00 0.00 0.00 0.00
02:43:28 PM eth0 6788.40 66614.00 462.58 95525.76 0.00 0.00 0.00 0.00
02:38:48 PM eth0 6777.00 65692.00 461.55 94104.06 0.00 0.00 0.00 0.00
02:17:08 PM eth0 6724.60 65014.40 457.81 92952.31 0.00 0.00 0.00 0.00
02:39:23 PM eth0 6660.00 64279.40 453.31 91934.52 0.00 0.00 0.00 0.00
02:19:23 PM eth0 6510.40 61964.00 442.66 88326.13 0.00 0.00 0.00 0.00
02:21:03 PM eth0 6486.20 62179.40 441.16 88787.42 0.00 0.00 0.00 0.00
看一下,有哪些网卡
[root@servera test]# sar -n DEV -f sar.data |awk '{ print $3}'|sort -u
0.04
277.73
310.95
eth0
eth1
IFACE
lo
(localhost.localdomain)
只有eth0,eth1 ,通过上面,主要也是eth1 比较高,
我们可以只分析eth1
[root@servera test]# sar -n DEV -f sar.data |grep eth1|grep -v Av| sort -nrk 4|head -50|sort -nk 1|head -50
02:05:33 PM eth1 2854.80 10199.60 198.95 14527.41 0.00 0.00 0.00 0.00
02:05:43 PM eth1 1.60 1.80 0.15 0.46 0.00 0.00 0.00 0.00
02:06:03 PM eth1 14060.60 49946.40 979.80 70534.26 0.00 0.00 0.00 0.00
02:06:08 PM eth1 5210.00 18400.80 362.70 25844.16 0.00 0.00 0.00 0.00
02:06:13 PM eth1 1.80 2.60 0.19 0.74 0.00 0.00 0.00 0.00
02:06:38 PM eth1 19228.20 67956.80 1339.44 95886.63 0.00 0.00 0.00 0.00
02:06:43 PM eth1 1.00 2.40 0.09 1.89 0.00 0.00 0.00 0.00
02:06:48 PM eth1 1.40 1.60 0.14 0.55 0.00 0.00 0.00 0.00
02:07:08 PM eth1 5157.20 17965.80 359.30 25521.96 0.00 0.00 0.00 0.00
02:07:13 PM eth1 16386.80 50546.40 1138.64 70990.08 0.00 0.00 0.00 0.00
02:07:18 PM eth1 1.80 1.80 0.17 0.66 0.00 0.00 0.00 0.00
02:07:43 PM eth1 14174.80 43442.80 985.06 61274.04 0.00 0.00 0.00 0.00
02:07:48 PM eth1 8311.60 25102.00 577.32 35157.07 0.00 0.00 0.00 0.00
02:08:13 PM eth1 1.80 2.40 0.19 0.63 0.00 0.00 0.00 0.00
02:08:18 PM eth1 22265.60 68059.00 1547.03 95642.32 0.00 0.00 0.00 0.00
02:08:23 PM eth1 76.00 225.20 5.27 318.99 0.00 0.00 0.00 0.00
02:08:48 PM eth1 3264.20 10163.20 227.14 14417.04 0.00 0.00 0.00 0.00
02:08:53 PM eth1 18895.40 58221.00 1312.88 82024.82 0.00 0.00 0.00 0.00
02:09:13 PM eth1 1.20 2.80 0.11 1.93 0.00 0.00 0.00 0.00
02:09:18 PM eth1 1.40 1.60 0.14 0.55 0.00 0.00 0.00 0.00
02:09:23 PM eth1 11534.80 35305.20 801.54 49867.00 0.00 0.00 0.00 0.00
02:09:28 PM eth1 11038.20 33218.60 766.71 46637.77 0.00 0.00 0.00 0.00
02:09:43 PM eth1 1.80 2.40 0.19 0.63 0.00 0.00 0.00 0.00
02:09:58 PM eth1 19547.20 60219.40 1358.53 84843.33 0.00 0.00 0.00 0.00
02:10:03 PM eth1 2650.00 8233.20 184.01 11584.95 0.00 0.00 0.00 0.00
02:10:18 PM eth1 1.80 2.00 0.18 0.58 0.00 0.00 0.00 0.00
02:10:28 PM eth1 49.20 174.40 3.70 251.23 0.00 0.00 0.00 0.00
02:10:33 PM eth1 22112.60 68220.40 1536.43 96148.16 0.00 0.00 0.00 0.00
02:10:48 PM eth1 1.00 1.00 0.10 0.29 0.00 0.00 0.00 0.00
02:11:03 PM eth1 1179.60 3729.00 82.04 5328.48 0.00 0.00 0.00 0.00
02:11:13 PM eth1 1.60 1.80 0.15 0.46 0.00 0.00 0.00 0.00
02:11:43 PM eth1 2.00 3.80 0.16 3.59 0.00 0.00 0.00 0.00
通过这个可以看出,从2:05就开始了,02:08最高,02:11后,就没有了。
到此,三个问题,就已经找出。
|