1、下载sysstat源码
sysstat源码下载地址:http://sebastien.godard.pagesperso-orange.fr
github https://github.com/sysstat/sysstat
这里示例所下载的版本是 sysstat-12.4.3.tar.xz
2、添加交叉编译工具链路径到环境变量
例如我的交叉编译工具链的路径是:
/home/share/toolchains/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/
那么执行:
# export PATH=$PATH:/home/share/toolchains/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin
3、解压、配置、编译sysstat
解压:
# tar xvf sysstat-12.4.3.tar.xz
# cd sysstat-12.4.3/
配置交叉编译工具及安装路径:
# ./configure --host=arm-linux CC=aarch64-linux-gnu-gcc --prefix=$PWD/install
编译安装:
# make && make install
4、编译完成,查看生成结果及文件类型
# ls install/bin/
cifsiostat iostat mpstat pidstat sadf sar tapestat
# ls install/lib/sa/
sa1 sa2 sadc
# file install/bin/sar
install/bin/sar: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=458f34ff080a1fca753ed10efbcee217a25bcaa8, stripped
5、上传到板子上测试
可以使用scp、ftp、lrzsz、tftp等命令,能把文件传到嵌入式设备上就行;
例如使用tftp,PC(IP:10.5.1.86)开启tftpd程序后,在嵌入式设备获取文件并添加执行权限:
# tftp -g -r sar 10.5.1.86
# chmod +x sar
# tftp -g -r sadc 10.5.1.86
# chmod +x sadc
# export PATH=$PATH:./
5.1 查看设备各个CPU使用率:
# sar -u -P ALL 1 1
Linux 4.14.139 (Ambarella) 01/01/70 _aarch64_ (4 CPU)
09:12:21 CPU %user %nice %system %iowait %steal %idle
09:12:22 all 13.66 0.00 4.64 0.00 0.00 81.70
09:12:22 0 27.27 0.00 2.02 0.00 0.00 70.71
09:12:22 1 12.37 0.00 5.15 0.00 0.00 82.47
09:12:22 2 14.29 0.00 7.14 0.00 0.00 78.57
09:12:22 3 0.00 0.00 4.26 0.00 0.00 95.74
Average: CPU %user %nice %system %iowait %steal %idle
Average: all 13.66 0.00 4.64 0.00 0.00 81.70
Average: 0 27.27 0.00 2.02 0.00 0.00 70.71
Average: 1 12.37 0.00 5.15 0.00 0.00 82.47
Average: 2 14.29 0.00 7.14 0.00 0.00 78.57
Average: 3 0.00 0.00 4.26 0.00 0.00 95.74
主要查看字段为idle及iowait,idle表示空闲率,过低代表CPU负载较高;iowait代表CPU等待IO百分比,过高代表系统存在I/O瓶颈;
5.2 查看IO统计信息
# sar -b 1 1
Linux 4.14.139 (Ambarella) 01/01/70 _aarch64_ (4 CPU)
10:00:55 tps rtps wtps dtps bread/s bwrtn/s bdscd/
s
10:00:56 1.00 0.00 1.00 0.00 0.00 16.00 0.0
0
Average: 1.00 0.00 1.00 0.00 0.00 16.00 0.0
0
其中tps为每秒IO总数;rtps/wtps,读/写磁盘IO总数;bread/bwrtn,读/写块总数;
5.3 查看磁盘(块设备)统计信息
# sar -d 1 1
Linux 4.14.139 (Ambarella) 01/01/70 _aarch64_ (4 CPU)
10:03:50 DEV tps rkB/s wkB/s dkB/s areq-sz aqu-s
z await %util
10:03:51 mmcblk0 2.00 0.00 8.00 0.00 4.00 0.0
1 2.50 0.30
Average: DEV tps rkB/s wkB/s dkB/s areq-sz aqu-s
z await %util
Average: mmcblk0 2.00 0.00 8.00 0.00 4.00 0.0
1 2.50 0.30
await为磁盘操作耗时(毫秒);util为被IO消耗的CPU占比;
5.4 查看设备内存使用率
# sar -r 1 1
Linux 4.14.139 (Ambarella) 01/01/70 _aarch64_ (4 CPU)
09:14:36 kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommi
t %commit kbactive kbinact kbdirty
09:14:37 438576 481492 505176 49.49 12312 52308 70398
0 68.96 67324 39332 8
Average: 438576 481492 505176 49.49 12312 52308 70398
0 68.96 67324 39332 8
memused为使用内存所占百分比;
5.5 查看网络统计信息
# sar -n DEV 1 1
Linux 4.14.139 (Ambarella) 01/01/70 _aarch64_ (4 CPU)
10:06:05 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/
s rxmcst/s %ifutil
10:06:06 lo 0.00 0.00 0.00 0.00 0.00 0.0
0 0.00 0.00
10:06:06 eth0 24.00 1.00 1.12 0.16 0.00 0.0
0 0.00 0.00
Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/
s rxmcst/s %ifutil
Average: lo 0.00 0.00 0.00 0.00 0.00 0.0
0 0.00 0.00
Average: eth0 24.00 1.00 1.12 0.16 0.00 0.0
0 0.00 0.00
5.6 更多参数查看帮助
# 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 [ <keyword> [,...] | PSI | ALL ]
System load and pressure-stall statistics
Keywords are:
LOAD Queue length and load average statistics [A_QUEUE]
CPU Pressure-stall CPU statistics [A_PSI_CPU]
IO Pressure-stall I/O statistics [A_PSI_IO]
MEM Pressure-stall memory statistics [A_PSI_MEM]
-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]