目录
1.背景介绍
2. sar 介绍
3. sar 使用
3.1 参数说明
3.2 监控指定网口带宽、速率
1.背景介绍
需要监控网口带宽
2. sar 介绍
sar 是一个强大的系统性能监控工具,属于 sysstat 工具包的一部分。它可以收集和报告系统的 CPU、内存、I/O、网络等多方面的性能数据,并支持历史数据的记录和查询,非常适合用于长期性能监控和问题诊断
3. sar 使用
3.1 参数说明
sar 参数说明,使用介绍 [root@idpa DBMirror]# 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] [root@idpa DBMirror]#3.2 监控指定网口带宽、速率
# 使用说明:sar -n DEV <终端输出时间间隔> | grep <网口名> e.g: sar -n DEV 1 | grep swift95f0 # ****************************************************************** # 网口 swift95f0 [root@idpa DBMirror]# ifconfig swift95f0 swift95f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 11.1.1.90 netmask 255.255.255.0 broadcast 0.0.0.0 ether 8c:1f:64:c3:a3:76 txqueuelen 1000 (Ethernet) RX packets 738090294 bytes 853972044999 (795.3 GiB) RX errors 4498 dropped 4283 overruns 24955 frame 4498 TX packets 49401 bytes 48508006 (46.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 # 网口 swift95f1 [root@idpa DBMirror]# [root@idpa DBMirror]# ifconfig swift95f1 swift95f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 11.2.1.90 netmask 255.255.255.0 broadcast 0.0.0.0 ether 8c:1f:64:c3:a3:78 txqueuelen 1000 (Ethernet) RX packets 1698847085 bytes 521746294730 (485.9 GiB) RX errors 269 dropped 47419 overruns 125975 frame 269 TX packets 35371294 bytes 25530764108 (23.7 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 # ****************************************************************** # 监控网口 swift95f0 # 注意:sar 监控网口时不会退出,需要 Ctrl+C 强制退出 [root@idpa DBMirror]# [root@idpa DBMirror]# sar -n DEV 1 | grep swift95f0 09:26:44 AM swift95f0 7866.00 0.00 8384.40 0.00 0.00 0.00 0.00 0.69 09:26:45 AM swift95f0 7864.00 0.00 8380.38 0.00 0.00 0.00 0.00 0.69 09:26:46 AM swift95f0 7864.00 0.00 8380.38 0.00 0.00 0.00 0.00 0.69 09:26:47 AM swift95f0 7866.00 0.00 8384.40 0.00 0.00 0.00 0.00 0.69 09:26:48 AM swift95f0 7866.00 0.00 8384.40 0.00 0.00 0.00 0.00 0.69 ^C[root@idpa DBMirror]# # ****************************************************************** # 监控网口 swift95f1 # 注意:sar 监控网口时不会退出,需要 Ctrl+C 强制退出 [root@idpa DBMirror]# [root@idpa DBMirror]# [root@idpa DBMirror]# sar -n DEV 1 | grep swift95f1 09:26:52 AM swift95f1 26631.00 0.00 1196.31 0.00 0.00 0.00 0.00 0.10 09:26:53 AM swift95f1 26667.00 0.00 1197.93 0.00 0.00 0.00 0.00 0.10 09:26:54 AM swift95f1 26733.00 0.00 1200.90 0.00 0.00 0.00 0.00 0.10 09:26:55 AM swift95f1 26751.00 0.00 1201.71 0.00 0.00 0.00 0.00 0.10 09:26:56 AM swift95f1 26829.00 0.00 1205.21 0.00 0.00 0.00 0.00 0.10 09:26:57 AM swift95f1 26918.00 0.00 1209.21 0.00 0.00 0.00 0.00 0.10 ^C[root@idpa DBMirror]# [root@idpa DBMirror]# # 注意: 1. sar 监控网口时不会退出,需要 Ctrl+C 强制退出 2. sar 监控输出每项意义: 时间 接口 rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil rxpck/s : 每秒接收包(pck)数量 txpck/s : 每秒发送包(pck)数量 rxkB/s: 每秒接收 XX kB 的数据 e.g: 比如 rxkB/s=8384.40 KB/秒 8384 KB/秒 = 8384/1024 MB/秒 = (8384/1024)*8 Mb/每秒 = (8384/1024)*8 Mbps %ifutil: 网卡利用率到此已完成监控网卡带宽与流量