sar(System Activity Reporter)
系统活动情况报告
是 Linux 上系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况、系统调用的使用情况、磁盘I/O、CPU使用率、内存、进程活动及IPC有关的活动等。
安装
apt install sysstat
help
$ 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]
示例
cpu
# CPU 10s 才一次,连续采用 3 次
$ sar -u -o sys_info 10 3
06:08:58 PM CPU %user %nice %system %iowait %steal %idle
06:09:08 PM all 0.15 0.00 0.71 0.00 0.00 99.14
# 所有 cpu 的使用情况
$ sar -P ALL 1 1
# cpu 0 的使用情况
$ sar -P 0 1 1
- all 所有 CPU 的平均值
- %user 用户级别(application)运行使用 CPU 总时间的百分比
- %nice 用户级别nice操作,所占用 CPU 总时间的百分比
- %system 核心级别(kernel)运行所使用 CPU 总时间的百分比
- %iowait 等待I/O操作占用 CPU 总时间的百分比
- %steal 管理程序(hypervisor)为另一个虚拟进程提供服务而等待虚拟 CPU 的百分比
- %idle CPU 空闲时间占用 CPU 总时间的百分比
inode、文件
$ sar -v 10 3
06:15:20 PM dentunusd file-nr inode-nr pty-nr
06:15:30 PM 68314 5280 93959 2
- dentunusd 目录高速缓存中未被使用的条目数量
- file-nr 文件句柄(file handle)的使用数量
- inode-nr 索引节点句柄(inode handle)的使用数量
- pty-nr 使用的pty使用数量
内存和交换空间
$ sar -r 10 3
06:19:06 PM kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
06:19:16 PM 435412 2831872 721388 18.03 90388 2362628 4001904 80.90 1223572 1719976 36
其他监控见help