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)
[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)
[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)