有很多工具可以实现该功能,一般会采用独立的监控服务器来实现网卡参数的收集并生成可是报告,但有时候需要简单、快速的查看一个参数,此时小巧的工具则变得更加符合我们的要求。
1. 静态查看某一个时刻网络端口数据
sar命令工具是不错的选择,该命令可以查看很多其他的参数,比如cpu使用情况、内存的使用情况等等,具体可以使用man来查看细节。以下主要针对网络做一个介绍,sar通过读取/proc and /sys目录下的信息。
命令: sar -n DEV 1 2 --human
#输出所有网络接口的使用参数,-n DEV代表网络接口,--human代表显示数值以易读性输出,比如1kb,2KB等。
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 每秒钟收到的数据大小Kb
Total number of kilobytes received per second.
txkB/s 每秒钟传送的数据大小Kb
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 网络接口的使用率。半双工接口使用接收与发送数据之和来计算网络接口的速度。全双工使用发送或者接口数据来计算
Utilization percentage of the network interface. For half-duplex inter‐
faces, utilization is calculated using the sum of rxkB/s and txkB/s as a
percentage of the interface speed. For full-duplex, this is the greater of
rxkB/S or txkB/s.
2. 动态实时查看某一个网络接口的链接状态
nload 则是实时读取 /sys/class/net/*/* /proc/net/dev 文件中的参数来显示内容的。
命令: nload devices enp6s0
#devices 后跟网卡的名称,网卡名称可以使用ip add 或者ifconfig 来查看
输出结果有两部分,incoming 接收到的数据,outgoing 发送的数据。